code: public String replace(CharSequence text, CharSequence replacement)
      {
          try
          {
              if (text.length() == 0)
              {
                  if (acceptEmpty)
                  {
                      return "";
                  }
              }
              CharArrayWriter caw = new CharArrayWriter();
              InputReader reader = Input.getInstance(text);
              ObsoleteSimpleReplacer fsp = new ObsoleteSimpleReplacer(replacement);
              replace(reader, caw, fsp);
              return caw.toString();
          }
          catch (IOException ex)
          {
              throw new IllegalArgumentException("can't happen", ex);
          }
      }
docs: Replaces regular expression matches in text with replacement string
  @param text
  @param replacement
  @return