List of utility methods to do Wildcard to Regex
String | wildcard2Regex(final String wildcard) wildcard Regex StringBuffer s = new StringBuffer((int) (wildcard.length() * 1.3)); String w = wildcard; for (int i = 0, is = w.length(); i < is; i++) { char c = w.charAt(i); switch (c) { case '*': s.append(".*"); break; ... |
String | wildcard2regexp(String wildcard) Compile wildcard to regexp StringBuffer sb = new StringBuffer("^"); for (int i = 0; i < wildcard.length(); i++) { char c = wildcard.charAt(i); switch (c) { case '.': sb.append("\\."); break; case '*': ... |
String | wildcardAsRegex(String patternWithWildcards) converts a string containing wildcards (* and ?) into a valid regex if (patternWithWildcards == null) { throw new IllegalArgumentException("patternWithWildcards must not be null"); return "\\Q" + patternWithWildcards.replace("?", "\\E.\\Q").replace("*", "\\E.*\\Q") + "\\E"; |
String | wildcardAsRegex(String wildcard) convert a wild card containing * and ? StringBuilder sb = new StringBuilder(); for (int i = 0; i < wildcard.length(); i++) { final char c = wildcard.charAt(i); switch (c) { case '*': sb.append(".*?"); break; case '?': ... |
String | wildcardToJavaRegex(String expr) wildcard To Java Regex if (expr == null) { throw new IllegalArgumentException("expr is null"); String regex = expr.replaceAll("([(){}\\[\\].+^$])", "\\\\$1"); regex = regex.replaceAll("\\*", ".*"); regex = regex.replaceAll("\\?", "."); return regex; |
String | wildcardToJavaRegexp(String expr) wildcard To Java Regexp if (expr == null) { throw new IllegalArgumentException("expr is null"); String regex = expr.replaceAll("([(){}\\[\\].+^$])", "\\\\$1"); regex = regex.replaceAll("\\*", ".*"); regex = regex.replaceAll("\\?", "."); return regex; |
String | wildcardToRegex(CharSequence s) wildcard To Regex StringBuilder sb = new StringBuilder(); int len = s.length(); for (int i = 0; i < len; i++) { char ch = s.charAt(i); switch (ch) { case '*': sb.append(".*"); break; ... |
String | wildcardToRegex(final String input) wildcard To Regex StringBuilder sb = new StringBuilder(input.length() + 10); sb.append('^'); for (int i = 0; i < input.length(); ++i) { char c = input.charAt(i); if (c == '*') { sb.append(".*"); } else if (c == '?') { sb.append('.'); ... |
String | wildcardToRegex(final String pattern) wildcard To Regex if (pattern == null) { return null; return pattern.replace("*", ".*").replace("?", "."); |
String | wildcardToRegex(String toSearch, boolean supportSQLWildcard) Convert a string that is expected to have standard "filename wildcards" to a matching regular expression. StringBuilder s = new StringBuilder(toSearch.length() + 5); s.append('^'); for (int i = 0, is = toSearch.length(); i < is; i++) { char c = toSearch.charAt(i); if (c == '*' || (c == '%' && supportSQLWildcard)) s.append(".*"); } else if (c == '?') { ... |