You need to replace everything but [a-zA-Z0-9.-].
The ^ within the brackets stands for “NOT”.
myString = myString.replaceAll("[^a-zA-Z0-9\\.\\-]", "_");
You need to replace everything but [a-zA-Z0-9.-].
The ^ within the brackets stands for “NOT”.
myString = myString.replaceAll("[^a-zA-Z0-9\\.\\-]", "_");