我想匹配「錯誤」的任何變體(讓我們假設整個棋盤上不區分大小寫),其中可能有也可能不跟隨字符,並且可能有或沒有「s」。如果一個字符跟隨另一個字符(可選),我不想匹配
例如,如果它具有以下,返回匹配的行:
text error: more text
text error more text
text errors more text
text errors(more text
text errors: more text
text errors:more text
但如果有一個等號後不久,我不希望它返回的行。例如:
text errors= more text
基本上,在「error」或「errors」後面有一個「=」符號時,它總是「錯誤」。
我無法想出比這更:
(?i)errors?[^\=]
不區分大小寫,字符E,R,R,O,R,也許一個s,而不是接着是「= 「是我閱讀的方式。
1 sample text, more text, errors=123456 more text more text
2 drops=0 link status good errors=0 adapter
3 Error: process failed to start
4 process [ERROR] failed
5 this line might have both ERROR and error=5555 and more text
6 there might be a line that has error=0x02343329 ERROR and more text
我想線3,4,5,和6被返回,而不是1或2。
不具有成功。我在這裏先向您的幫助表示感謝。
'errors?'使整個字符串'errors'可選。這可能是爲什麼3-6沒有返回。你會想'錯誤(s?)'而不是。 – dzieciou
也等號需要轉義,所以你應該有'='而不是'\ ='。 – dzieciou
@dzieciou「錯誤?使整個字符串錯誤可選。」< - 錯誤,它只能使'''可選 – fge