Reputation: 971
I'm just trying a few examples and I'm kind of stuck with this one:
(&[^#|amp|quot|apos])
It's capturing an extra character after '&'.
a &a text with & an &f and &#
Captures &a and &f.
How to capture & only?
Upvotes: 0
Views: 53
Reputation: 26667
What you are looking for is negative look ahead. You can write it as
&(?!#|amp|quot|apos)
Regex Explanation
&
Matches a single &
(?!#|amp|quot|apos)
Negative look ahead. Check if the &
is not followed by #
or amp
or quot
or apos
.
What is wrong with (&[^#|amp|quot|apos])
[^#|amp|quot|apos]
This doesn't translate to amp
or quot
or apos
. This is a character class which translate to #
or |
or a
or m
or p
etc.Upvotes: 2