title: Replace text with data & matched group contents
body: <p>I don't believe I saw this when searching (believe me, I spent a good amount of time searching for this) for a solution to this so here goes.</p>
  
  <p>Goal:
  Match regex in a string and replace it with something that contains the matched value.</p>
  
  <p>Regex used currently:</p>
  
  <pre><code>\b(Connor|charries96|Foo|Bar)\b
  </code></pre>
  
  <p><em>For the record I suck at regex incase this isn't the best way to do it.</em></p>
  
  <p>My current code (and several other methods I tried) can only replace the text with the first match it encounters if there are multiple matches.</p>
  
  <pre><code>private Pattern regexFromList(List&lt;String&gt; input) {
      if(input.size() &lt; 1) {
          return "";
      }
  
      StringBuilder builder = new StringBuilder();
      builder.append("\\b");
      builder.append("(");
      for(String s : input) {
          builder.append(s);
          if(!s.equals(input.get(input.size() - 1)))
          {
              builder.append("|");
          }
      }
      builder.append(")");
      builder.append("\\b");
  
      return Pattern.compile(builder.toString(), Pattern.CASE_INSENSITIVE);
  }
  </code></pre>
  
  <p>Example input:</p>
  
  <pre><code>charries96's name is Connor.
  </code></pre>
  
  <p>Example result using TEST as the data to prepend the match with</p>
  
  <pre><code>TESTcharries96's name is TESTcharries96.
  </code></pre>
  
  <p>Desired result using example input:</p>
  
  <pre><code>TESTcharries96's name is TESTConnor.
  </code></pre>
  
  <p>Here is my current code for replacing the text:</p>
  
  <pre><code>if(highlight) {
      StringBuilder builder = new StringBuilder();
      Matcher match = pattern.matcher(event.getMessage());
      String string = event.getMessage();
  
      if (match.find()) {
          string = match.replaceAll("TEST" + match.group());
          // I do realise I'm using #replaceAll but that's mainly given it gives me the same result as other methods so why not just cut to the chase.
      }
      builder.append(string);
      return builder.toString();
   }
  </code></pre>
  
  <p><strong>EDIT:</strong>
  Working example of desired result on <a href="http://regexr.com/39p7u" rel="nofollow">RegExr</a></p>