问题:
I know it's possible to match a word and then reverse the matches using other tools (eg grep -v
). 我知道可以匹配一个单词,然后使用其他工具(例如grep -v
)反转匹配。 However, is it possible to match lines that do not contain a specific word, eg hede
, using a regular expression? 但是,是否可以使用正则表达式匹配不包含特定单词(例如hede
)的行?
Input: 输入:
hoho
hihi
haha
hede
Code: 码:
grep "<Regex for 'doesn't contain hede'>" input
Desired output: 所需的输出:
hoho
hihi
haha
解决方案:
参考一: https://stackoom.com/question/1hg6/正则表达式匹配不包含单词的行参考二: https://oldbug.net/q/1hg6/Regular-expression-to-match-a-line-that-doesn-t-contain-a-word
来源:oschina
链接:https://my.oschina.net/u/3797416/blog/3209794