Open top menu








You need to remove or replaces some Special Character eg- Backslash (\n), [ , ’, and \n ,\u,\s, etc. You replaces some regular expressions are complicated things,

String str="hello, who are \u you";
 
Step 1- The (\u )escape character replace very complicated.

String value=str. replaceAll(Pattern.quote("\\u") , "new String value");
 
 
Step 2- the replace  all digit Value from String.

String str="hello, who are 24314 you ";

String something=str.replaceAll(
"[\\p{Digit}]", "");

Output:-hello who are you

Step 3- The replace  all regular expression from String.

String alphaOnly = input.replaceAll("[^a-zA-Z]+","");
String alphaAndDigits = input.replaceAll(
"[^a-zA-Z0-9]+","");
 
 Or equivalent

String alphaOnly = input.replaceAll(
"[^\\p{Alpha}]+","");
String alphaAndDigits = input.replaceAll(
"[^\\p{Alpha}\\p{Digit}]+","");









 thank you  

0 comments