I am parsing through some XML and sanitizing some fields.
I'm trying to do the following in Java:
nameField = nameField.replaceAll("[^a-zA-Z\\d\\s\\.,'&]", "");
I do not want to replace any letters of the alphabet, any number, any whitespace, any period, any comma, any single quote or (this is where my issue is) the literal string &.
But I do want to replace occurrences of a single & or a single ;
But obviously my Regex as it sits won't work. It'll leave in all & and all ;.
For example, say the string of K&W@#9$9(AR;.0 O& is found, my expected result would be: KW99AR.0 O&.
How can I achieve this?
&inside character class will match&,a,m,por;.