I have some String in this form
You can use a negated character class like this:
str = str.replaceAll("[^\\d.]+", "");
[^\\d.] will match any character that is not a digit and not a DOT.
\D also includes whitespace so both don't need to be provided in a regex.