正则表达式不运行 [英] Regex NOT Operation

查看:134
本文介绍了正则表达式不运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有条件选择任何不属于span标签的部分。

输入 -

 < span class ='ptc- highlightedSearchResult'>活塞和LT; /跨度>它们的< span class ='ptc-highlightedSearchResult'> ROD< / span> ring 

正则表达式选择< span> 标签和它的内容 -

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

我可以选择任何跨度及其内容,但不能以其他方式进行。任何有关NOT操作的帮助将不胜感激。

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

regex101演示



它将匹配任何不在开始和结束标记之间的文本或者在开始和结束标记之间的任何文本。演示中存在正则表达式的细分。


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.

解决方案

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.

这篇关于正则表达式不运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆