I have a string "Home 333-666-8888 Do Not Disturb" and want to extract the numbers from the string. For that I found a solution with ReplaceAll functionality in Java.
String ab="Home 333-666-8888 Do Not Disturb";
String bc=ab.replaceAll("[^0-9-]", "");
And it gives me 333-666-8888
My concern is how does replaceAll
functionality actually works? I used to assume that it would replace the things matching the Regular Expression with blank and return me Home Do Not Disturb
. But It gives me 333-666-8888
. Can anyone help me in understanding how replaceAll with Regular Expression Works?