Return numbers from a String

1

I am programmer PHP and maintaining a project Java I saw myself with the need to return only numbers contained in a certain String .

I did not find any questions about this in SOpt and I found it in SOen, so I bring this question here to know what is the best option, since in Java because it is a lower level language, everything or almost everything does difference in processing and can always be optimized ...

An example of what I'm requesting:

String cnpj = "83.411.122/0001-06";

The expected return:

"83411122000106"
    
asked by anonymous 10.11.2016 / 18:38

1 answer

3

Solution found in SOen :

str = str.replaceAll("\D+","");
    
10.11.2016 / 18:38