Problem with existing attempt
The reason for the unsuccessful template &[ ]|[^(?*^( ));] Is because you have | but there is no bounding box - this means that you are replacing &[ ] OR [^(?*^( ));] - and this last will fit most things - you are also a misunderstanding of how character classes work.
Inside [ .. ] (the character class) there are a few simple rules:
- if it starts with
^ , it is denied, otherwise ^ is a literal. - if there is a hyphen, it is considered as a range (for example, az or 1-5)
- if there is a backslash, it either marks the abbreviated class (for example,
\w ), or escapes the next character (inside the char class, this is only required for [ ] ^ - \ ). - you use only one character (taking into account any qualifiers); there is no order / sequence in the class, and duplicates of the same character are ignored.
In addition, you do not need to put a space inside the character class - the literal space works fine (unless you are in the comment mode with free space, which should be explicitly included).
Hope this helps you understand what is going wrong?
Regarding the actual solution to your problem ...
Decision
To map an ampersand that does not run an HTML object, you can use:
&(?![az][a-z0-9]+;|#(?:\d+|x[\dA-F]+);)
That is, an ampersand followed by a negative result for any of:
letter, then letter or number, semicolon - that is, a reference to a named object
a hash, then either a number or x, followed by a hexadecimal number, and finally a semicolon - that is, a reference to a numerical object.
To use this in CFML, replace & with & will be:
<cfset data = rereplaceNoCase( data , '&(?![az][a-z0-9]+;|##(?:\d+|x[\dA-F]+);)' , '&' , 'all' ) />
source share