user3554045 user3554045 - 2 years ago 151
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.

Answer Source

using parenthetical capture groups:

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

or, using lookarounds:

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


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download