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

如何否定整个正则表达式?

发布时间:2020-12-14 06:46:51 所属栏目:百科 来源:网络整理
导读:我有一个正则表达式,例如(ma |(t){1})。它匹配ma和t并且不匹配bla。 我想否定正则表达式,因此它必须匹配bla,而不是ma和t,通过添加一些东西到这个正则表达式。我知道我可以写bla,但实际的正则表达式更复杂。 使用负外观:(?!pattern) 正环境可用于断言
我有一个正则表达式,例如(ma |(t){1})。它匹配ma和t并且不匹配bla。

我想否定正则表达式,因此它必须匹配bla,而不是ma和t,通过添加一些东西到这个正则表达式。我知道我可以写bla,但实际的正则表达式更复杂。

使用负外观:(?!pattern)

正环境可用于断言模式匹配。负面的周转是相反的:它用于断言一个模式不匹配。一些香精支持断言;一些对后视等进行限制。

链接到regular-expressions.info

> Lookahead and Lookbehind Zero-Width Assertions
> Flavor comparison

也可以看看

> How do I convert CamelCase into human-readable names in Java?
> Regex for all strings not containing a string?
> A regex to match a substring that isn’t followed by a certain other substring.

更多例子

这些都是尝试为玩具问题提供正则表达式解决方案作为练习;如果你想学习各种可以使用环视(嵌套它们,使用它们捕获等)的方法,它们应该是有教育意义的:

> codingBat plusOut using regex
> codingBat repeatEnd using regex
> codingbat wordEnds using regex

(编辑:李大同)

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

    推荐文章
      热点阅读