MCPcopy Create free account
hub / github.com/5zig/The-5zig-Mod / compileMatchPattern

Method compileMatchPattern

Utils/src/eu/the5zig/util/Utils.java:494–509  ·  view source on GitHub ↗
(String match)

Source from the content-addressed store, hash-verified

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

Callers 6

matchesMethod · 0.95
containsMethod · 0.95
setMessageMethod · 0.95
addServerMethod · 0.95
setServerMethod · 0.95
tryIgnoreMessageMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected