code: public static String replaceFirst(CharSequence self, Pattern pattern, CharSequence replacement) {
          return pattern.matcher(self).replaceFirst(replacement.toString());
      }
docs: Replaces the first substring of a CharSequence that matches the given
  compiled regular expression with the given replacement.
  <p>
  Note that backslashes (<tt>\</tt>) and dollar signs (<tt>$</tt>) in the
  replacement string may cause the results to be different than if it were
  being treated as a literal replacement string; see
  {@link java.util.regex.Matcher#replaceFirst}.
  Use {@link java.util.regex.Matcher#quoteReplacement} to suppress the special
  meaning of these characters, if desired.
  <p>
  <pre class="groovyTestCase">
  assert "foo".replaceFirst('o', 'X') == 'fXo'
  </pre>
  
  @param   self the CharSequence that is to be matched
  @param   pattern the regex Pattern to which the CharSequence of interest is to be matched
  @param   replacement the CharSequence to be substituted for the first match
  @return  The resulting <tt>String</tt>
  @see #replaceFirst(String, java.util.regex.Pattern, String)
  @since 1.8.2