# How to replace all special character of a string using java

For example i have a string:

String s = "Now& uyu876876 %\$#^%*&^*&^*&";

I want to remove all character of a string using java. How to do?

If you want replace all special character use below code:

s.replaceAll("[^a-zA-Z0-9]+","");

or else if u want to replace only specific chars use below code

s.replaceAll("[()?:!.,;]+", ""); // you can add/remove based on your requirement