Java Utililty Methods Wildcard to Regex

List of utility methods to do Wildcard to Regex

Description

The list of methods to do Wildcard to Regex are organized into topic(s).

Method

StringwildcardToRegex(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;
...
StringwildcardToRegex(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;
...
StringwildcardToRegex(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(".");
...
StringwildcardToRegexp(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] == '*') {
...
StringwildcardToRegexString(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;
...