code: public static String replaceAll(String source, Pattern pattern, Handler<String, String> handler)
    {
      Matcher matcher = pattern.matcher(source);
      StringBuilder builder = new StringBuilder();
      int start = 0;
      while(matcher.find(start)) {
        builder.append(source.substring(start, matcher.start()));
        if(matcher.groupCount() == 0) {
          builder.append(handler.handle(source.substring(matcher.start(), matcher.end())));
        }
        else {
          for(int i = 0; i < matcher.groupCount(); ++i) {
            builder.append(handler.handle(matcher.group(i + 1)));
          }
        }
        start = matcher.end();
      }
      builder.append(source.substring(start));
      return builder.toString();
    }
docs: Replace all pattern occurrences using match transformer. This method is the standard replace all but allows for
  matched pattern transformation via caller code handler. Common usage is to supply match transformer as anonymous
  instance of {@link Handler} interface. If {@link Handler#handle(Object)} method returns given <code>match</code>
  value replace all degrade to standard behavior, and of course there is no need to use it.
  
  <pre>
  Pattern pattern = Pattern.compile(&quot;i&quot;);
  String text = Strings.replaceAll(&quot;This is a text&quot;, pattern, new Handler&lt;String, String&gt;()
  {
  public String handle(String match)
  {
  return &quot;&lt;em&gt;&quot; + match + &quot;&lt;/em&gt;&quot;;
  }
  });
  </pre>
  
  In above sample code, after replace all, <code>text</code> will be <em>Th&lt;em&gt;i&lt;/em&gt;s
  &lt;em&gt;i&lt;/em&gt;s a text</em>.
  
  @param source source string,
  @param pattern pattern to look for,
  @param handler match transformer.
  @return new string with pattern replaced.