user3554045 user3554045 - 5 months ago 19x
Java Question

Java - Regex to replace dot between numbers Only

Regular expression to replace dot between two numbers Only.

for example replace 3.4 to 3xx4 ,,,,, 12.45 to 12xx45

replace all occurrences to above pattern from string

Dots may appear after sentence end, or at any other position; but i want to replace dot that appears between numbers only.


using parenthetical capture groups:

 input = input.replaceAll("(\\d+)\\.(\\d+)", "$1xx$2");

or, using lookarounds:

 input = input.replaceAll("(?<=\\d)\\.(?=\\d)", "xx");