If you want to replace all non-alphanumeric using regex, you can use one of the following ways:

1
return value.replaceAll("[^A-Za-z0-9]", "");

or

1
return value.replaceAll("[\\W]|_", "");

or

1
return value.replaceAll("\\P{Alnum}", "");

Comments