RegexUtils { public static Pattern wildcardsToPattern(final String text) { ArgumentChecker.notNull(text, "text"); StringTokenizer tkn = new StringTokenizer(text, "?*", true); StringBuilder buf = new StringBuilder(text.length() + 10); buf.append('^'); boolean lastStar = false; while (tkn.hasMoreTokens()) { String str = tkn.nextToken(); if (str.equals("?")) { buf.append('.'); lastStar = false; } else if (str.equals("*")) { if (lastStar == false) { buf.append(".*"); } lastStar = true; } else { buf.append(Pattern.quote(str)); lastStar = false; } } buf.append('$'); return Pattern.compile(buf.toString(), Pattern.CASE_INSENSITIVE); } 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(expectedExceptions = IllegalArgumentException.class) public void test_null() { assertEquals(null, RegexUtils.wildcardsToPattern(null)); }