I have a long string. I want to replace all matches with the part of the corresponding regular expression (group).
For instance:
String = "This is a great day, is it not? If there is something, THIS IS it. <b>is</b>".
I want to replace all the words "is"
with, say, "<h1>is</h1>"
. The case should remain the same as the original. So the last line I want is:
This <h1>is</h1> a great day, <h1>is</h1> it not? If there <h1>is</h1> something, THIS <h1>IS</h1> it. <b><h1>is</h1></b>.
The regex that I tried:
Pattern pattern = Pattern.compile("[.>, ](is)[.<, ]", Pattern.CASE_INSENSITIVE);
source share