title: How to appendReplacement on a Matcher group instead of the whole pattern?
body: <p>I am using a <code>while(matcher.find())</code> to loop through all of the matches of a Pattern.  For each instance or match of that pattern it finds, I want to replace <code>matcher.group(3)</code> with some new text.  This text will be different for each one so I am using <code>matcher.appendReplacement()</code> to rebuild the original string with the new changes as it goes through. However, <code>appendReplacement()</code> replaces the entire Pattern instead of just the group.</p>
  
  <p>How can I do this but only modify the third group of the match rather than the entire Pattern?</p>
  
  <p>Here is some example code:</p>
  
  <pre><code>Pattern pattern = Pattern.compile("THE (REGEX) (EXPRESSION) (WITH MULTIPLE) GROUPS");
  Matcher matcher = pattern.matcher("THE TEXT TO SEARCH AND MODIFY");
  StringBuffer buffer = new StringBuffer();
  
  while(matcher.find()){
     matcher.appendReplacement(buffer, processTheGroup(matcher.group(3));
  }
  </code></pre>
  
  <p>but I would like to do something like this (obviously this doesn't work).</p>
  
  <pre><code>...
  while(matcher.find()){
     matcher.group(3).appendReplacement(buffer, processTheGroup(matcher.group(3));
  }
  </code></pre>
  
  <p>Something like that, where it only replaces a certain group, not the whole Pattern.</p>
  
  <p><em>EDIT:  changed the regex example to show that not all of the pattern is grouped.</em></p>