Remove the plus sign from the beginning and replace spaces with numbers
5 answers
You can use the following to match (simple approach):
\D //(any non digit)
And replace with ''
(empty string)
See DEMO
Code:
str = str.replaceAll("\\D", "");
Edit: If your string is part of another string, use the following:
(?<=\d)\s+(?=\d)|\+(?=\d)
See DEMO
Explanation:
-
(?<=\d)\\s+(?=\d)
All spaces surrounded by numbers -
\+(?=\d)
plus sign at the beginning of digits
+2
source to share