RegexUtils { public static boolean matches(String input, Pattern pattern) { Matcher m = pattern.matcher(input); return m.matches(); } private  RegexUtils(); static Pattern wildcardsToPattern(final String text); static Pattern globToPattern(String glob); static boolean wildcardMatch(final String searchCriteriaWithWildcard, final String textToMatchAgainst); static boolean containsWildcard(final String searchCriteria); static String extract(String string, String regex); static String extract(String string, String regex, int group); static String extract(String string, Pattern pattern, int group); static boolean matches(String input, Pattern pattern);  }
@Test public void globMatches() { assertTrue(matches("foo?bar", "fooxbar")); assertFalse(matches("foo?bar", "foobar")); assertFalse(matches("foo?bar", "fooxxbar")); assertTrue(matches("foo*bar", "fooxxbar")); assertTrue(matches("foo*bar", "fooxbar")); assertTrue(matches("foo*bar", "foobar")); assertTrue(matches("foo%bar", "fooxxbar")); assertTrue(matches("foo%bar", "fooxbar")); assertTrue(matches("foo%bar", "foobar")); assertFalse(matches("?foo%bar", "foobar")); assertTrue(matches("?foo%bar", "xfoobar")); assertTrue(matches("?foo%bar", "xfooxbar")); assertTrue(matches("?foo%bar", "xfooxxbar")); assertTrue(matches("f??oo%bar", "fxxooxxbar")); assertFalse(matches("f??oo%bar", "fxooxxbar")); assertTrue(matches("$?^", "$A^")); assertTrue(matches("$*^", "$ABC^")); assertTrue(matches("$%^", "$ABC^")); }