How to appendReplacement on a Matcher group instead of the whole pattern?
I am using a while(matcher.find()) to loop through all of the matches of a Pattern. For each instance or match of that pattern it finds, I want to replace matcher.group(3) with some new text. This text will be different for each one so I am using matcher.appendReplacement() to rebuild the original string with the new changes as it goes through. However, appendReplacement() replaces the entire Pattern instead of just the group. How can I do this but only modify the third group of the match rather than the entire Pattern? Here is some example code: Pattern pattern = Pattern.compile("THE (REGEX)