FileSystemUtils { @VisibleForTesting public static String wildcardToRegexp(String globExp) { StringBuilder dst = new StringBuilder(); char[] src = globExp.replace("**/*", "**").toCharArray(); int i = 0; while (i < src.length) { char c = src[i++]; switch (c) { case '*': if (i < src.length && src[i] == '*') { dst.append(".*"); ++i; } else { dst.append("[^/]*"); } break; case '?': dst.append("[^/]"); break; case '.': case '+': case '{': case '}': case '(': case ')': case '|': case '^': case '$': dst.append('\\').append(c); break; case '\\': i = doubleSlashes(dst, src, i); break; default: dst.append(c); break; } } return dst.toString(); }  @VisibleForTesting static String wildcardToRegexp(String globExp);  }
@Test public void testGlobTranslation() { assertEquals("foo", wildcardToRegexp("foo")); assertEquals("fo[^/]*o", wildcardToRegexp("fo*o")); assertEquals("f[^/]*o\\.[^/]", wildcardToRegexp("f*o.?")); assertEquals("foo-[0-9][^/]*", wildcardToRegexp("foo-[0-9]*")); assertEquals("foo-[0-9].*", wildcardToRegexp("foo-[0-9]**")); assertEquals(".*foo", wildcardToRegexp("**[^/]*/[^/]*", wildcardToRegexp("foo*")); assertEquals("foo/[^/]*/.*", wildcardToRegexp("foo/*/**")); assertEquals("foo.*baz", wildcardToRegexp("foo**baz")); assertEquals("foo\\\\", wildcardToRegexp("foo\\")); assertEquals("foo/bar\\\\baz[^/]*", wildcardToRegexp("foo/bar\\baz*")); }