Java Wildcard to Regex wildcardToRegex(CharSequence s)

Here you can find the source of wildcardToRegex(CharSequence s)

Description

wildcard To Regex

License

Open Source License

Declaration

public static String wildcardToRegex(CharSequence s) 

Method Source Code

//package com.java2s;
//it under the terms of the GNU Affero General Public License as published by

public class Main {
    public static String wildcardToRegex(CharSequence s) {
        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;
            case '?':
                sb.append(".");
                break;
            case '[':
            case ']':
            case '(':
            case ')':
            case '{':
            case '}':
            case '|':
            case '+':
            case '-':
            case '^':
            case '$':
            case '\\':
            case '.':
                sb.append("\\").append(ch);
                break;
            default:
                sb.append(ch);/*from  www . jav a2  s. c om*/
                break;
            }
        }
        return sb.toString();
    }
}

Related

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