user488469 user488469 - 1 month ago 5x
Java Question

Extract digits from a string in Java

I have a Java

object. I need to extract only digits from it. I'll give an example:

I want

Is there a library function that extracts only digits?

Thanks for the answers. Before I try these I need to know if I have to install any additional llibraries?


You can use regex and delete non-digits.

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