Friday, July 8, 2016

[TIPS] Extract digit or non-digit from String using JAVA

Single line command to extract digit from a String
Eg. text = All (68)

text = text.replaceAll("\\D+", "");

Output - text = 68

Now \D represent the digit character i.e. 68
Also \d represent the non-digit character i.e. All ()
+ represent one or more time