String s = "sf9897&^%fdferf";
s = s.replaceAll("[^0-9a-zA-Z]","");
System.out.print(s);
String str = "sf9%897&^%fdferf";
str = str .replaceAll("[^0-9a-zA-Z]+","");
System.out.print(str);
\w A word character: [a-zA-Z_0-9]
\W A non-word character: [^\w]