I have no idea how to remove invalid characters from a string in Java. I'm trying to remove all the characters that are not numbers, letters, or ( ) [ ] . How can I do this?
Thanks
See Question&Answers more detail:osI have no idea how to remove invalid characters from a string in Java. I'm trying to remove all the characters that are not numbers, letters, or ( ) [ ] . How can I do this?
Thanks
See Question&Answers more detail:osString foo = "this is a thing with & in it";
foo = foo.replaceAll("[^A-Za-z0-9()\[\]]", "");
Javadocs are your friend. Regular expressions are also your friend.
Edit:
That being siad, this is only for the Latin alphabet; you can adjust accordingly. \w
can be used for a-zA-Z
to denote a "word" character if that works for your case though it includes _
.