I have some strings like:
String a = "Hello 12 2 3 4 45th World!";
I wanna concatenate numbers as: "Hello 12234 45th World"
By trying a.replaceAll("(?<=\\d) +(?=\\d)", "")
, I got the result as:
"Hello 1223445th World"
.
Is there any way to concatenate only numbers, not number+th?
(?<=\\d) +(?=\\d+(?:\\s|$))
You can try this.See demo.
https://regex101.com/r/nS2lT4/43
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With