private static Pattern compilePattern(final String s){
  StringBuilder rc=new StringBuilder();
  for (int i=0; i < s.length(); i++) {
    char ch=s.charAt(i);
switch (ch) {
case '?':
      rc.append('.');
    break;
case '*':
  rc.append(".*");
break;
case '.':
rc.append('\\');
default :
rc.append(ch);
}
}
return Pattern.compile(rc.toString());
}

private static Pattern compilePattern ( final String s ) { StringBuilder rc = new StringBuilder ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char ch = s . charAt ( i ) ; switch ( ch ) { case '?' : rc . append ( '.' ) ; break ; case '*' : rc . append ( ".*" ) ; break ; case '.' : rc . append ( '\\' ) ; default : rc . append ( ch ) ; } } return Pattern . compile ( rc . toString ( ) ) ; }
convert host pattern from glob format to regexp . note that the function assumes a valid host pattern , so characters that might not happen in the host name but must be escaped in regular expressions are not escaped .
