我对正则表达式相当陌生,需要一些帮助。我需要在 Perl 中使用正则表达式过滤一些行。我要将正则表达式传递给另一个函数,因此需要在一行中完成。
我只想选择包含 "too long"
的行并且不以 "SKIPPING"
开头
这是我的测试字符串:
SKIPPING this bond since maturity too long
TKIPPING this bond since maturity too long
SLAPPING this bond since maturity too long
Hello this maturity too long
this is too long
hello there
正则表达式规则应与“太长”上的以下内容匹配:
SKIPPING this bond since maturity too long
SLAPPING this bond since maturity too long
Hello this maturity too long
this is too long
它应该跳过:
"hello there" because it doesn't contain 'too long'
"SKIPPING this bond since maturity too long" because it containst 'SKIPPING'
最佳答案
/^(?!SKIPPING).*too long/
关于regex - 如何在正则表达式中结合正面和负面条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1308719/