The regular expression:
(?-imsx:&[^(amp;)|(lt;)|(gt;)])
matches as follows:
NODE EXPLANATION
----------------------------------------------------------------------
(?-imsx: group, but do not capture (case-sensitive)
(with ^ and $ matching normally) (with . not
matching \n) (matching whitespace and #
normally):
----------------------------------------------------------------------
& '&'
----------------------------------------------------------------------
[^(amp;)|(lt;)|(gt;) any character except: '(', 'a', 'm', 'p',
] ';', ')', '|', '(', 'l', 't', ';', ')',
'|', '(', 'g', 't', ';', ')'
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
and for mine
The regular expression:
(?-imsx:(&(?!(?:amp|lt|gt);)|[><]))
matches as follows:
NODE EXPLANATION
----------------------------------------------------------------------
(?-imsx: group, but do not capture (case-sensitive)
(with ^ and $ matching normally) (with . not
matching \n) (matching whitespace and #
normally):
----------------------------------------------------------------------
( group and capture to \1:
----------------------------------------------------------------------
& '&'
----------------------------------------------------------------------
(?! look ahead to see if there is not:
----------------------------------------------------------------------
(?: group, but do not capture:
----------------------------------------------------------------------
amp 'amp'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
lt 'lt'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
gt 'gt'
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
; ';'
----------------------------------------------------------------------
) end of look-ahead
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[><] any character of: '>', '<'
----------------------------------------------------------------------
) end of \1
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
and your new regex
The regular expression:
(?-imsx:&(?!(amp;)|(lt;)|(gt;)))
matches as follows:
NODE EXPLANATION
----------------------------------------------------------------------
(?-imsx: group, but do not capture (case-sensitive)
(with ^ and $ matching normally) (with . not
matching \n) (matching whitespace and #
normally):
----------------------------------------------------------------------
& '&'
----------------------------------------------------------------------
(?! look ahead to see if there is not:
----------------------------------------------------------------------
( group and capture to \1:
----------------------------------------------------------------------
amp; 'amp;'
----------------------------------------------------------------------
) end of \1
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
( group and capture to \2:
----------------------------------------------------------------------
lt; 'lt;'
----------------------------------------------------------------------
) end of \2
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
( group and capture to \3:
----------------------------------------------------------------------
gt; 'gt;'
----------------------------------------------------------------------
) end of \3
----------------------------------------------------------------------
) end of look-ahead
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
poj |