List of utility methods to do Wildcard to Regex
String | wildcardToRegex(String wildcard) wildcard To Regex StringBuffer s = new StringBuffer(wildcard.length()); boolean alternation = false; for (int i = 0, is = wildcard.length(); i < is; i++) { char c = wildcard.charAt(i); switch (c) { case '*': s.append(".*"); break; ... |
String | wildcardToRegex(String wildcard) Converts given string containing wildcards (* or ?) to its corresponding regular expression. StringBuffer s = new StringBuffer(wildcard.length()); s.append('^'); for (int i = 0, is = wildcard.length(); i < is; i++) { char c = wildcard.charAt(i); switch (c) { case '*': s.append(".*"); break; ... |
String | wildcardToRegex(String wildcardPattern) wildcard To Regex if (wildcardPattern != null && (wildcardPattern.indexOf("*") != -1 || wildcardPattern.indexOf("?") != -1)) { StringBuffer buffer = new StringBuffer(); char[] chars = wildcardPattern.toCharArray(); for (char aChar : chars) { if (aChar == '*') buffer.append(".*"); else if (aChar == '?') buffer.append("."); ... |
String | wildcardToRegexp(String globExp) Expands glob expressions to regular expressions. 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] == '*') { ... |
String | wildcardToRegexString(String wildcard) Convert strings containing DOS-style '*' or '?' StringBuilder s = new StringBuilder(wildcard.length()); s.append('^'); for (int i = 0, is = wildcard.length(); i < is; i++) { char c = wildcard.charAt(i); switch (c) { case '*': s.append(".*"); break; ... |