protected static boolean regexReplace(JTextArea textArea,String toFind,String replaceWith,boolean forward,boolean matchCase,boolean wholeWord) throws PatternSyntaxException {
  Caret c=textArea.getCaret();
  int start=makeMarkAndDotEqual(textArea,forward);
  String findIn=getFindInText(textArea,start,forward);
  if (findIn == null)   return false;
  RegExReplaceInfo info=getRegExReplaceInfo(toFind,findIn,forward,matchCase,wholeWord,replaceWith);
  findIn=null;
  if (info != null) {
    c.setSelectionVisible(true);
    int matchStart=info.getStartIndex();
    int matchEnd=info.getEndIndex();
    if (forward) {
      matchStart+=start;
      matchEnd+=start;
    }
    selectAndPossiblyCenter(textArea,matchStart,matchEnd);
    textArea.replaceSelection(info.getReplacement());
    return true;
  }
  return false;
}

protected static boolean regexReplace ( JTextArea textArea , String toFind , String replaceWith , boolean forward , boolean matchCase , boolean wholeWord ) throws PatternSyntaxException { Caret c = textArea . getCaret ( ) ; int start = makeMarkAndDotEqual ( textArea , forward ) ; String findIn = getFindInText ( textArea , start , forward ) ; if ( findIn == null ) return false ; RegExReplaceInfo info = getRegExReplaceInfo ( toFind , findIn , forward , matchCase , wholeWord , replaceWith ) ; findIn = null ; if ( info != null ) { c . setSelectionVisible ( true ) ; int matchStart = info . getStartIndex ( ) ; int matchEnd = info . getEndIndex ( ) ; if ( forward ) { matchStart += start ; matchEnd += start ; } selectAndPossiblyCenter ( textArea , matchStart , matchEnd ) ; textArea . replaceSelection ( info . getReplacement ( ) ) ; return true ; } return false ; }
finds the next instance of the regular expression specified from the caret position . if a match is found , it is replaced with the specified replacement string .
