正则表达式匹配与号但未转义的 xml 字符 [英] Regex Match Ampersand but not escaped xml characters

查看:31
本文介绍了正则表达式匹配与号但未转义的 xml 字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想匹配与号 (&) 但当它以下列方式存在时不匹配

I would like to match ampersand (&) but not when it exists in following manner

'
"
>
<
&
&#

所以在下面一行<代码>&我的&名称是 M&Hh.&apos;"&gt;&lt;&amp;&# &&&&&&

我希望它匹配除存在于<代码>&apos;"&gt;&lt;&amp;&#

推荐答案

这看起来像是否定前瞻断言:

&(?!(?:apos|quot|[gl]t|amp);|#)

应该可以.

说明:

&        # Match &
(?!      # only if it's not followed by
 (?:     # either
  apos   # apos
 |quot   # or quot
 |[gl]t  # or gt/lt
 |amp    # or amp
 );      # and a semicolon
|        # or
 \#      # a hash
)        # End of lookahead assertion

这篇关于正则表达式匹配与号但未转义的 xml 字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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