Regex Match Ampersand but not escaped xml characters

后端 未结 1 1487
梦如初夏
梦如初夏 2020-12-17 10:18

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

'
"
>
<
&
&#

相关标签:
1条回答
  • 2020-12-17 10:46

    That looks like a job for negative lookahead assertions:

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

    should work.

    Explanation:

    &        # 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
    
    0 讨论(0)
提交回复
热议问题