Java String remove all non numeric characters but keep the decimal separator

Try this code:

String str = "a12.334tyz.78x";
str = str.replaceAll("[^\\d.]", "");

Now str will contain "12.334.78".

Leave a Comment