public static int replaceAll(RTextArea textArea,String toFind,String replaceWith,boolean matchCase,boolean wholeWord,boolean regex) throws PatternSyntaxException {
  int count=0;
  textArea.beginAtomicEdit();
  try {
    if (regex) {
      if (replaceWith == null) {
        replaceWith="";
      }
      int oldOffs=textArea.getCaretPosition();
      textArea.setCaretPosition(0);
      int flags=Pattern.MULTILINE;
      flags|=matchCase ? 0 : Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE;
      Pattern p=Pattern.compile(toFind,flags);
      while (SearchEngine.find(textArea,toFind,true,matchCase,wholeWord,true)) {
        Matcher m=p.matcher(textArea.getSelectedText());
        String replacement=getReplacementText(m,replaceWith);
        textArea.replaceSelection(replacement);
        count++;
      }
      if (count == 0) {
        textArea.setCaretPosition(oldOffs);
      }
    }
 else {
      textArea.setCaretPosition(0);
      while (SearchEngine.find(textArea,toFind,true,matchCase,wholeWord,false)) {
        textArea.replaceSelection(replaceWith);
        count++;
      }
    }
  }
  finally {
    textArea.endAtomicEdit();
  }
  return count;
}

public static int replaceAll ( RTextArea textArea , String toFind , String replaceWith , boolean matchCase , boolean wholeWord , boolean regex ) throws PatternSyntaxException { int count = 0 ; textArea . beginAtomicEdit ( ) ; try { if ( regex ) { if ( replaceWith == null ) { replaceWith = "" ; } int oldOffs = textArea . getCaretPosition ( ) ; textArea . setCaretPosition ( 0 ) ; int flags = Pattern . MULTILINE ; flags |= matchCase ? 0 : Pattern . CASE_INSENSITIVE | Pattern . UNICODE_CASE ; Pattern p = Pattern . compile ( toFind , flags ) ; while ( SearchEngine . find ( textArea , toFind , true , matchCase , wholeWord , true ) ) { Matcher m = p . matcher ( textArea . getSelectedText ( ) ) ; String replacement = getReplacementText ( m , replaceWith ) ; textArea . replaceSelection ( replacement ) ; count ++ ; } if ( count == 0 ) { textArea . setCaretPosition ( oldOffs ) ; } } else { textArea . setCaretPosition ( 0 ) ; while ( SearchEngine . find ( textArea , toFind , true , matchCase , wholeWord , false ) ) { textArea . replaceSelection ( replaceWith ) ; count ++ ; } } } finally { textArea . endAtomicEdit ( ) ; } return count ; }
replaces all instances of the text / regular expression specified in the specified document with the specified replacement .
