public static String escapeRegex(final String regex){
  Matcher match=REGEX_CHARS.matcher(regex);
  return match.replaceAll("\\\\$1");
}

public static String escapeRegex ( final String regex ) { Matcher match = REGEX_CHARS . matcher ( regex ) ; return match . replaceAll ( "\\\\$1" ) ; }
this function will escape special characters within a string to ensure that the string will not be parsed as a regular expression . this is helpful with accepting using input that needs to be used in functions that take a regular expression as an argument ( such as string . replaceall ( ) , or string . split ( ) ) .
