Regex NOT Operation

丶灬走出姿态 提交于 2019-12-13 04:32:47

问题


I have condition where I have to select anything which is not part of span tag.

Input -

the <span class='ptc-highlightedSearchResult'>PISTON</span> has their <span class='ptc-highlightedSearchResult'>ROD</span> ring

regex which selects <span> tag and it's content -

(<span[^>]+class\s*=\s*("|')ptc-highlightedSearchResult\2[^>]*>)[^<]*(</span>)

I'm able to select whatever comes in span and their content but not otherwise. Any help on NOT operation will be appreciated.


回答1:


You can use this:

((?:(?![^<>]*(?:>))[^<](?![^<>]*</))+)

regex101 demo

It will match any text not inside or between opening and closing tags. There's a breakdown of the regex in the demo.



来源:https://stackoverflow.com/questions/19109356/regex-not-operation

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