static String jsRegExpToJavaRegExp ( String re ) { re = re . replaceAll ( "\\[\\^\\\\\\d\\]" , "." ) ; re = re . replaceAll ( "\\[([^\\]]*)\\\\b([^\\]]*)\\]" , "[$1\\\\cH$2]" ) ; // [...\b...] // -> // [...\cH...] re = re . replaceAll ( "(?<!\\\\)\\[([^((?<!\\\\)\\[)\\]]*)\\[" , "[$1\\\\[" ) ; // [...[...] // -> // [...\[...] // back reference in character classes are simply ignored by browsers re = re . replaceAll ( "(?<!\\\\)\\[([^\\]]*)(?<!\\\\)\\\\\\d" , "[$1" ) ; // [...ab\5cd...] // -> // [...abcd...] // characters escaped without need should be "un-escaped" re = re . replaceAll ( "(?<!\\\\)\\\\([ACE-RT-VX-Zaeg-mpqyz])" , "$1" ) ; re = escapeJSCurly ( re ) ; return re ; }
Transform a JavaScript regular expression to a Java regular expression