Changing regex line number in java

I am new to regex and asked a quick question about using this. I have a phone number as a string, and I need to delete all the special characters and just leave the numbers. for example, if the number

(555) 555-5555

I would like to get the result 5555555555

Is it possible to use regex to execute this java?

+3
source share
1 answer
String ph = "(555) 555-5555";
ph = ph.replaceAll("\\D","");

\\Dis short for non-digital. Therefore, we replace every asymmetry in the string with nothing, effectively removing them.

+4
source

All Articles