I think this is a very common problem, but couldn't find a related question in SO or any other tutorial as well. So if it's a duplicate, feel free to mark as such.
Well here is the problem, I have a
String and I would like to replace all the words
test in it to
tested. But I don't want to replace the word if it's contained inside a
this test is <other test end> should be replaced by
this tested is <other test end>.
So i have create a regex
(?:<.*?>)|(test) (anything inside
<> should be a non-capturing group and all other
test should be match.
But as I understand
Matcher.group(0) will match even the non-capturing group. And what's worse is
Matcher.replaceAll() seems to replace the non-capturing group text as well?
How can I solve this? Is there any way I can specify
replaceAll() to replace only
Is there some other easy and clean way to solve this problem?