GlobToRegex { public static String toRegex(String glob, String separators) { return new GlobToRegex(glob, separators).convert(); } private  GlobToRegex(String glob, String separators); static String toRegex(String glob, String separators);  }
@Test public void testPathGlob(){ String sep = "/"; Pattern pattern; Matcher matcher; String glob01 = "/a*"; String path01_01 = "/a"; String path01_02 = "/abc"; String path01_03 = "/a*"; String path01_04 = "/a/"; String path01_05 = "/abc/"; String path01_06 = "/abc/a"; String path01_07 = "/abc/b"; String path01_08 = "/abc/a/a"; String path01_09 = "/abc/a/b"; String path01_10 = "/abc/b/a"; String path01_11 = "/abc/b/b"; System.out.println(GlobToRegex.toRegex( glob01, sep)); pattern = Pattern.compile(GlobToRegex.toRegex( glob01, sep)); matcher = pattern.matcher(path01_01); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_02); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_03); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_04); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_05); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_06); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_07); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_08); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_09); System.out.println(matcher.matches()); String glob02 = "/a****/a"; System.out.println(PathUtils.normalizeRegex(glob04) ); System.out.println(GlobToRegex.toRegex( glob04, sep)); pattern = Pattern.compile(GlobToRegex.toRegex( glob04, sep)); matcher = pattern.matcher(path01_01); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_02); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_03); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_04); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_05); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_06); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_07); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_08); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_09); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_10); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_11); System.out.println(matcher.matches()); String glob05 = "/a*/**a"; System.out.println(PathUtils.normalizeRegex(glob05)); System.out.println(GlobToRegex.toRegex( glob05, sep)); pattern = Pattern.compile(GlobToRegex.toRegex( glob05, sep)); matcher = pattern.matcher(path01_01); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_02); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_03); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_04); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_05); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_06); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_07); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_08); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_09); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_10); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_11); System.out.println(matcher.matches()); String glob06 = "/abc/**a"; System.out.println(PathUtils.normalizeRegex(glob06)); System.out.println(GlobToRegex.toRegex( glob06, sep)); pattern = Pattern.compile(GlobToRegex.toRegex( glob06, sep)); matcher = pattern.matcher(path01_01); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_02); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_03); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_04); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_05); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_06); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_07); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_08); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_09); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_10); System.out.println(matcher.matches()); matcher = pattern.matcher(path01_11); System.out.println(matcher.matches()); }