I have a string in my Java program which is read from database.
This may contain special characters in between as below:
I would write
theString.replaceAll("\\W","");
This will remove everything except for letters, numbers and underscores.