in reply to Can't figure out how to invert this regex

If I recall, an entity can be only alphanums, so this should do it:
s/&(?![A-Za-z0-9]+;)/REPLACED/g;
Literally: an ampersand not followed by (1 or more alphanums followed by a semicolon).

If that's not the correct definition of an entity, season to taste.

Not sure why you were looking to the left to determine ampersandy-ness. The interesting part is to the right.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.


update: Ahh yes, the pound form. And the #x form. OK, try this:
s/&(?!(?:[A-Za-z0-9]+|#\d+|#x[0-9A-Fa-f]+);)/REPLACED/g;

Replies are listed 'Best First'.
Re^2: Can't figure out how to invert this regex
by Anonymous Monk on Nov 25, 2005 at 15:05 UTC
    actually, an entity can also have the form { so there would be a need to check for a pound as well as alpha-num.
Re^2: Can't figure out how to invert this regex
by Anonymous Monk on Nov 25, 2005 at 15:03 UTC
    "Not sure why you were looking to the left to determine ampersandy-ness."

    Just a mistake out of my own inexperience with regex's. I didn't really understand where it was looking. Now I get it.