public TextEditor replaceAll(String regex,String replacement){
  if (text.length() > 0) {
    final String r=replacement;
    Pattern p=Pattern.compile(regex,Pattern.MULTILINE);
    Matcher m=p.matcher(text);
    StringBuffer sb=new StringBuffer();
    while (m.find()) {
      m.appendReplacement(sb,r);
    }
    m.appendTail(sb);
    text=sb;
  }
  return this;
}

public TextEditor replaceAll ( String regex , String replacement ) { if ( text . length ( ) > 0 ) { final String r = replacement ; Pattern p = Pattern . compile ( regex , Pattern . MULTILINE ) ; Matcher m = p . matcher ( text ) ; StringBuffer sb = new StringBuffer ( ) ; while ( m . find ( ) ) { m . appendReplacement ( sb , r ) ; } m . appendTail ( sb ) ; text = sb ; } return this ; }
replace all occurrences of the regular expression with the replacement . the replacement string can contain $ 1 , $ 2 etc . referring to matched groups in the regular expression .
