question: public static String javaUtilRegexEscape ( String s ) { if ( s . indexOf ( "\\E" ) == - 1 ) { return "\\Q" + s + "\\E" ; } StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { sb . append ( '\\' ) ; sb . append ( s . charAt ( i ) ) ; } return sb . toString ( ) ; }
target:  Escapes the special characters from a string so it can be used as part of a regex pattern. This method is for use on regexes in the flavor of the java.util.regex package. This method should be removed when we move to the java version 1.5 (Tiger) release, since that release gives us a literal regex flag as well as a quote method to produce literal regexes.