Extract digits from a string in Java October 11, 2022 by Tarik You can use regex and delete non-digits. str = str.replaceAll("\\D+","");