Java Wildcard to Regex wildcardToRegex(final String input)

Here you can find the source of wildcardToRegex(final String input)

Description

wildcard To Regex

License

Open Source License

Declaration

private static String wildcardToRegex(final String input) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    private static String wildcardToRegex(final String input) {
        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('.');
            } else if ("\\.[]{}()+-^$|".indexOf(c) >= 0) {
                sb.append('\\');
                sb.append(c);/*  w w w .j a  v a  2  s .  c o  m*/
            } else {
                sb.append(c);
            }
        }
        sb.append('$');
        return sb.toString();
    }
}

Related

  1. wildcardAsRegex(String patternWithWildcards)
  2. wildcardAsRegex(String wildcard)
  3. wildcardToJavaRegex(String expr)
  4. wildcardToJavaRegexp(String expr)
  5. wildcardToRegex(CharSequence s)
  6. wildcardToRegex(final String pattern)
  7. wildcardToRegex(String toSearch, boolean supportSQLWildcard)
  8. wildcardToRegex(String wildcard)
  9. wildcardToRegex(String wildcard)