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

标签 regex perl regex-negation lookahead negative-lookahead

我对正则表达式相当陌生,需要一些帮助。我需要在 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/

相关文章:

Java 正则表达式查找或替换第一次出现而不丢失尾部文本

python - URL正则表达式帮助

perl - WWW::Mechanize::Chrome 如何关闭选项卡

除多字符标记之外的任何内容的正则表达式

c# - 使用负向后查找来匹配字符串中的单词

Java正则表达式匹配数字、字符、逗号和引号...

regex - 如何在正则表达式中匹配比较运算符

perl - Perl 样板应该放在包声明之前还是之后?

perl - 我如何检查一个文件是否被另一个 Perl 程序打开?

正则表达式说什么不匹配?