正则表达式块否定 [英] Regular Expression block negation
本文介绍了正则表达式块否定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想找出一个没有出现特定标签的字符串,例如:
I want to find out a string in which a particular tag does not occur, such as:
<xyz>[\w]+<[^(unwanted)]></xyz>
其中 unwanted
将被解释为 a
, d
, e
, n
>、t
和 u
.但我想要的是一个块字符串.我如何用正则表达式表达它?我试过消极前瞻,但不起作用:
where unwanted
will be interpreted as a
, d
, e
, n
, t
and u
. But what I want is a block string. How can I express it in regular expression?
I have tried negative lookahead, which doesn't work:
<xyz>.+(?!unwanted).+</xyz>
推荐答案
<xyz>(?:(?!unwanted).)+</xyz>
匹配 <xyz>...</xyz>
中的所有字符,但前提是表达式 unwanted
不以任何字符开头.
Matches all chars in <xyz>...</xyz>
, but only as long as the expression unwanted
doesn't start at any of them.
这篇关于正则表达式块否定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文