String filter = "a-zA-Z0-9äöüÄÖÜß-\\.";
"^[^" + filter + "]*$", ""
inputtext.replaceAll("^[^" + filter + "]*$", "");
This Java RegEx filter should remove all characters from inputtext except the characters in filter, but I’m getting an exception that says that the dot is not allowed. I already escaped the dot with two slashes.
What’s wrong?
Move the
-to the end:A dash indicates a character range and a dot is not a valid end of a range. You also do not want to define a range there. Moving it to the end solves the problem.
Btw. if you want to remove all characters that do not match your filter you need to change the replace:
the way you have it, it will only replace if all characters are not in that class.