public TextEditor replaceAll(Pattern pattern,Replacement replacement){
  Matcher m=pattern.matcher(text);
  int lastIndex=0;
  StringBuilder sb=new StringBuilder();
  while (m.find()) {
    sb.append(text.subSequence(lastIndex,m.start()));
    sb.append(replacement.replacement(m));
    lastIndex=m.end();
  }
  sb.append(text.subSequence(lastIndex,text.length()));
  text=sb;
  return this;
}

public TextEditor replaceAll ( Pattern pattern , Replacement replacement ) { Matcher m = pattern . matcher ( text ) ; int lastIndex = 0 ; StringBuilder sb = new StringBuilder ( ) ; while ( m . find ( ) ) { sb . append ( text . subSequence ( lastIndex , m . start ( ) ) ) ; sb . append ( replacement . replacement ( m ) ) ; lastIndex = m . end ( ) ; } sb . append ( text . subSequence ( lastIndex , text . length ( ) ) ) ; text = sb ; return this ; }
replace all occurrences of the pattern . the replacement object ' s replace ( ) method is called on each match , and it provides a replacement , which is placed literally ( i . e . , without interpreting $ 1 , $ 2 etc . )
