private static Pattern makePatternFromWildcard(String pattern){
  StringBuilder regexp=new StringBuilder();
  for (int i=0, len=pattern.length(); i < len; i++) {
    char c=pattern.charAt(i);
switch (c) {
case '*':
      int toIncrement=0;
    if (len > i + 1 && pattern.charAt(i + 1) == '*') {
      toIncrement=1;
      if (len > i + 2 && pattern.charAt(i + 2) == '/') {
        toIncrement=2;
      }
 else       if (len == i + 2 && i > 0 && pattern.charAt(i - 1) == '/') {
        regexp.delete(regexp.length() - 1,regexp.length());
      }
    }
  regexp.append(".*");
i+=toIncrement;
break;
case '?':
regexp.append('.');
break;
case '^':
case '$':
case '|':
case '+':
case '{':
case '}':
case '[':
case ']':
case '\\':
case '.':
regexp.append('\\');
regexp.append(c);
break;
default :
regexp.append(c);
break;
}
}
return Pattern.compile(regexp.toString());
}

private static Pattern makePatternFromWildcard ( String pattern ) { StringBuilder regexp = new StringBuilder ( ) ; for ( int i = 0 , len = pattern . length ( ) ; i < len ; i ++ ) { char c = pattern . charAt ( i ) ; switch ( c ) { case '*' : int toIncrement = 0 ; if ( len > i + 1 && pattern . charAt ( i + 1 ) == '*' ) { toIncrement = 1 ; if ( len > i + 2 && pattern . charAt ( i + 2 ) == '/' ) { toIncrement = 2 ; } else if ( len == i + 2 && i > 0 && pattern . charAt ( i - 1 ) == '/' ) { regexp . delete ( regexp . length ( ) - 1 , regexp . length ( ) ) ; } } regexp . append ( ".*" ) ; i += toIncrement ; break ; case '?' : regexp . append ( '.' ) ; break ; case '^' : case '$' : case '|' : case '+' : case '{' : case '}' : case '[' : case ']' : case '\\' : case '.' : regexp . append ( '\\' ) ; regexp . append ( c ) ; break ; default : regexp . append ( c ) ; break ; } } return Pattern . compile ( regexp . toString ( ) ) ; }
returns a regular expression implementing a matcher for " pattern " , in which " * " and " ? " are wildcards . < p > e . g . " foo * bar ? . java " - > " foo . * bar . \ \ . java "
