I’ve searched several posts that might provide the answer I need, but I could not find one.
I wonder why this regex:
Pattern.compile("[^\\w\\s\\d\\&]")
Would not work properly on a String like:
"AE&E randomstr§%%%ing b§)$§$/bla & some text"
The outcome would be (as tested):
"AE E randomstring blabla some text"
Although I specifically excluded the ampersand. Does the previous tokens overrule it? Can anyone clarify the logic behind this?
My code:
String str = "AE&E randomstr§%%%ing b45747bla & some text";
Pattern pattern = Pattern.compile("[^\\w\\s\\d\\&]");
Matcher matcher = pattern.matcher(str);
str = StringUtils.normalizeSpace(matcher.replaceAll(" "));
I have to appologize. I swear I tried it unescaped and escaped and it seems to NOT work. Roddy of the Frozen Peas made me try once more, and MAGICALLY now the script does what it should.
Thanks to the commenters,
-solved!
working code: