Just run this code:

 

str = str.replaceAll("[^0-9]+","");

This means: replace everything that is not number with empty string (“”)