Это регулярное выражение найдет то, что вы хотите:
^(?=(?:(?!expir).)*$).*(?:error|warning)
Объяснение:
^ : 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" )
С файлом вроде:
error warning abc expir abc expir warning abc error expir def
это соответствует только строкам 1 и 2.