Regular Expression block negation

巧了我就是萌 提交于 2019-12-02 16:15:20

问题


I want to find out a string in which a particular tag does not occur, such as:

<xyz>[\w]+<[^(unwanted)]></xyz>

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>

回答1:


<xyz>(?:(?!unwanted).)+</xyz>

Matches all chars in <xyz>...</xyz>, but only as long as the expression unwanted doesn't start at any of them.



来源:https://stackoverflow.com/questions/14819125/regular-expression-block-negation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!