I would like to show only a-z0-9
in a string, and the other characters should be replaced by null string
String s=this.saveFileName.replaceAll("/[a-z0-9. ]/", "");
This those not work, any ideas why?
Try this:
String s = "abc123ABC!@#$%^;'xyz";
String newString = s.replaceAll("[^a-z0-9]", "");
//newString is now "abc123xyz"
This takes advantage of the negation (^) operator in character classes which basically says, "match everything except the following characters."
Also, you don't need slashes when defining Java regexes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With