How to replace every single characters, till the end of a line, using Java regex?
For Example: I want to replace every character with XXX right after = sign
contact.name=Stack Overflow
contact.name=XXX
Try this:
String example = "contact.name=Stack Overflow";
example = example.replaceAll("=.*", "=XXX");
This should take care of it
Matcher matcher = Pattern.compile("=(.*?)\n").matcher(string);
if (matcher.find()) {
string = string.substring(0, string.length - matcher.group(1).length);
for (int i = 0; i < matcher.group(1).length; i ++) {
string += "X";
}
}
replaceAll?