public static PathPattern from(String path) {
final Map<String, String> groups = U.map();
final AtomicInteger counter = new AtomicInteger();
String regex = Str.replace(path, PATH_PARAM_REGEX, new Mapper<String[], String>() {
@Override
public String map(String[] gr) throws Exception {
return toPathParamRegex(groups, counter, gr[1]);
}
});
if (regex.equals("/*")) {
regex = "/" + toPathParamRegex(groups, counter, ANY, ".*");
} else if (regex.endsWith("/*")) {
regex = Str.trimr(regex, "/*");
regex += U.frmt("(?:/%s)?", toPathParamRegex(groups, counter, ANY, ".*"));
}
Pattern pattern = Pattern.compile(regex);
return new PathPattern(path, pattern, groups);
}