public static String expandRegex(String regex){
  String newRegex=regex.replaceAll("\\\\d","[0-9]");
  newRegex=newRegex.replaceAll("\\\\D","[^0-9]");
  newRegex=newRegex.replaceAll("\\\\s","[ \\t\\n\\f\\r]");
  newRegex=newRegex.replaceAll("\\\\S","[^ \\t\\n\\f\\r]");
  newRegex=newRegex.replaceAll("\\\\w","[a-zA-Z_0-9]");
  newRegex=newRegex.replaceAll("\\\\W","[^a-zA-Z_0-9]");
  if (newRegex.startsWith("^"))   newRegex=newRegex.substring(1);
  if (newRegex.endsWith("$"))   newRegex=newRegex.substring(0,newRegex.length() - 1);
  newRegex=removeFlagExpressions(newRegex);
  newRegex=removeReluctantOperators(newRegex);
  return newRegex;
}

public static String expandRegex ( String regex ) { String newRegex = regex . replaceAll ( "\\\\d" , "[0-9]" ) ; newRegex = newRegex . replaceAll ( "\\\\D" , "[^0-9]" ) ; newRegex = newRegex . replaceAll ( "\\\\s" , "[ \\t\\n\\f\\r]" ) ; newRegex = newRegex . replaceAll ( "\\\\S" , "[^ \\t\\n\\f\\r]" ) ; newRegex = newRegex . replaceAll ( "\\\\w" , "[a-zA-Z_0-9]" ) ; newRegex = newRegex . replaceAll ( "\\\\W" , "[^a-zA-Z_0-9]" ) ; if ( newRegex . startsWith ( "^" ) ) newRegex = newRegex . substring ( 1 ) ; if ( newRegex . endsWith ( "$" ) ) newRegex = newRegex . substring ( 0 , newRegex . length ( ) - 1 ) ; newRegex = removeFlagExpressions ( newRegex ) ; newRegex = removeReluctantOperators ( newRegex ) ; return newRegex ; }
java regular expressions contain predefined character classes which the regex parser cannot handle
