Search code examples
javastringreplaceall

Replacing part of regex


I trying to replace '.' between two not number symbols. I used replaceAll and regEx

string.replaceAll("\\D\\.\\D", "_");

but it changing and symbols near '.' Can I solve this with Java methods or I should write own method?


Solution

  • this may work for you:

    yourString.replaceAll("(\\D)[.](\\D)","$1$2");