Regex: Find ampersands but ignore HTML entities
Hi,
I'm trying to write/find a regular expression for finding ampersands but not HTML entites
I have this which finds entities but can't quite figure out how to ignore entities and return unmatched "&"
Test string:
Code:
This is sample test containing a bunch of & and entities. Do you shop at: M&S? &x#1234;
I want to html encode the non-entity ampersands e.g.
"bunch of & and" --> "bunch of & and"
Any help will be greatly appreciated
Cheers Al
Re: Regex: Find ampersands but ignore HTML entities
Could you just look for ampersands with whitespace after them? E.g. pattern = "& " and replace with "& ".
Re: Regex: Find ampersands but ignore HTML entities
Samba,
Thanks for your reply, yes I guess that's an option but I was looking for something a little more bullet proof.
An option might be to surround any fields that might contain non-standard characters or & with the tag?
Al