我通过grep -E
使用以下正则表达式来匹配通过|
管道的特定字符串字符串。
$ git log <more switches here> | grep -E "match me"
输出:
match me once
match me twice
我真正想要的是一个否定匹配(返回所有不包含指定字符串的输出行,如下所示,但grep
不喜欢它:
$ git log <more switches here> | grep -E "^match me"
期望的输出:
whatever 1
whatever 2
这是从命令行返回的完整输出:
match me once
match me twice
whatever 1
whatever 2
如何根据负正则表达式匹配得到所需的输出?
答案 0 :(得分:7)
使用反转匹配的-v
选项,选择不匹配的行
grep -v 'match me'
另一种选择是使用-P
将模式解释为Perl正则表达式。
grep -P '^((?!match me).)*$'