加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 06:06:53 所属栏目:百科 来源:网络整理
导读:我对正则表达式相当新,需要一些帮助.我需要在Perl中使用正则表达式过滤一些行.我将把正则表达式传递给另一个函数,所以它需要在一行中完成. 我想只选择包含“太长”且不以“SKIPPING”开头的行 这是我的测试字符串: SKIPPING this bond since maturity too l
我对正则表达式相当新,需要一些帮助.我需要在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/

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读