1. 程式人生 > >正則表示式: 找出不含(排除)某個字串的所有

正則表示式: 找出不含(排除)某個字串的所有

Match string not containing string

Given a list of strings (words or other characters), only return the strings that do not match.


以正則表示式 ^((?!badword).)*$ 搜尋以下內容將會得到除1、4行以外的所有內容。此表示式對於log搜尋比較有用。

badword可以替換為一組字串,如(ECSdk|MOS),表示式^((?!(ECSdk|MOS)).)*$意為排除ECSdk和MOS 所在的行。

badword
test
one two
abadwords

three


參考:

https://www.regextester.com/15