question: 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 = new StringBuilder ( sb . toString ( ) ) ; } return this ; }
target:  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.