正則表達式匹配不包含單詞的行 - Regular expression to match a line that doesn't contain a word

問題:

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
相關文章
相關標籤/搜索