(String match)
| 492 | } |
| 493 | |
| 494 | public static Pattern compileMatchPattern(String match) { |
| 495 | // replace duplicate stars |
| 496 | // match = match.replaceAll("(\\*)\\1+", "*"); |
| 497 | |
| 498 | // replace any pair of backslashes by [*] |
| 499 | match = match.replaceAll("(?<!\\\\)(\\\\\\\\)+(?!\\\\)", "*"); |
| 500 | // minimize unescaped redundant wildcards |
| 501 | match = match.replaceAll("(?<!\\\\)[?]*[*][*?]+", "*"); |
| 502 | // escape unescaped regexps special chars, but [\], [?] and [*] |
| 503 | match = match.replaceAll("(?<!\\\\)([|\\[\\]{}(),.^$+-])", "\\\\$1"); |
| 504 | // replace unescaped [?] by [.?] |
| 505 | match = match.replaceAll("(?<!\\\\)[?]", "(.?)"); |
| 506 | // replace unescaped [*] by [.*] |
| 507 | match = match.replaceAll("(?<!\\\\)[*]", "(.*)"); |
| 508 | return Pattern.compile(match, Pattern.CASE_INSENSITIVE); |
| 509 | } |
| 510 | |
| 511 | public static String escapeStringForRegex(String string) { |
| 512 | // escape unescaped regexps special chars |
no outgoing calls
no test coverage detected