如何在正则表达式中结合正面和负面条件?

我对正则表达式相当新,需要一些帮助.我需要在Perl中使用正则表达式过滤一些行.我将把正则表达式传递给另一个函数,所以它需要在一行中完成.

我想只选择包含“太长”且不以“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/

转载注明原文:如何在正则表达式中结合正面和负面条件? - 代码日志