Regex To Remove Spaces Between Numbers Only
I need to remove the spaces between numbers only, so that a string like this: 'Hello 111 222 333 World!' becomes 'Hello 111222333 World!' I've tried this: message = message.repla
Solution 1:
You can use this lookaround based regex:
String repl ="Hello 111 222 333 World!".replaceAll("(?<=\\d) +(?=\\d)", "");
//=> Hello 111222333 World!
This regex "(?<=\\d) +(?=\\d)"
makes sure to match space that are preceded and followed by a digit.
Post a Comment for "Regex To Remove Spaces Between Numbers Only"