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

前端之家收集整理的这篇文章主要介绍了如何否定整个正则表达式?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个正则表达式,例如(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

原文链接:https://www.f2er.com/regex/358126.html

猜你在找的正则表达式相关文章