Diese Regex findet, was Sie wollen:
^(?=(?:(?!expir).)*$).*(?:error|warning)
Erläuterung:
^ : begining of line (?= : start lookahead (?: : start non capture group (?!expir) : negative lookahead, make sure w don'thave expir You may want to add wordboundaries if you don't want to match "expiration" (?!\bexpir\b) . : any character but newline )* : group may appear 0 or moe times $ : end of line ) : end of lookahead at this point we are sure we don't have "expir" in the line so, go to match the wanted words .* : 0 or more any character but newline (?: : start non capture group error : literally error, you could do "\berror\b" if you don't want to match "errors" | : OR warning : literally warning, you could do "\bwarning\b" if you don't want to match "warnings" )
Mit Datei wie:
error warning abc expir abc expir warning abc error expir def
es entspricht nur den Zeilen 1 und 2.