private static boolean match(CharSequence string,CharSequence pattern,int sNdx,int pNdx){
  int pLen=pattern.length();
  if (pLen == 1) {
    if (pattern.charAt(0) == '*') {
      return true;
    }
  }
  int sLen=string.length();
  boolean nextIsNotWildcard=false;
  while (true) {
    if ((sNdx >= sLen) == true) {
      while ((pNdx < pLen) && (pattern.charAt(pNdx) == '*')) {
        pNdx++;
      }
      return pNdx >= pLen;
    }
    if (pNdx >= pLen) {
      return false;
    }
    char p=pattern.charAt(pNdx);
    if (nextIsNotWildcard == false) {
      if (p == '\\') {
        pNdx++;
        nextIsNotWildcard=true;
        continue;
      }
      if (p == '?') {
        sNdx++;
        pNdx++;
        continue;
      }
      if (p == '*') {
        char pNext=0;
        if (pNdx + 1 < pLen) {
          pNext=pattern.charAt(pNdx + 1);
        }
        if (pNext == '*') {
          pNdx++;
          continue;
        }
        int i;
        pNdx++;
        for (i=string.length(); i >= sNdx; i--) {
          if (match(string,pattern,i,pNdx) == true) {
            return true;
          }
        }
        return false;
      }
    }
 else {
      nextIsNotWildcard=false;
    }
    if (p != string.charAt(sNdx)) {
      return false;
    }
    sNdx++;
    pNdx++;
  }
}

private static boolean match ( CharSequence string , CharSequence pattern , int sNdx , int pNdx ) { int pLen = pattern . length ( ) ; if ( pLen == 1 ) { if ( pattern . charAt ( 0 ) == '*' ) { return true ; } } int sLen = string . length ( ) ; boolean nextIsNotWildcard = false ; while ( true ) { if ( ( sNdx >= sLen ) == true ) { while ( ( pNdx < pLen ) && ( pattern . charAt ( pNdx ) == '*' ) ) { pNdx ++ ; } return pNdx >= pLen ; } if ( pNdx >= pLen ) { return false ; } char p = pattern . charAt ( pNdx ) ; if ( nextIsNotWildcard == false ) { if ( p == '\\' ) { pNdx ++ ; nextIsNotWildcard = true ; continue ; } if ( p == '?' ) { sNdx ++ ; pNdx ++ ; continue ; } if ( p == '*' ) { char pNext = 0 ; if ( pNdx + 1 < pLen ) { pNext = pattern . charAt ( pNdx + 1 ) ; } if ( pNext == '*' ) { pNdx ++ ; continue ; } int i ; pNdx ++ ; for ( i = string . length ( ) ; i >= sNdx ; i -- ) { if ( match ( string , pattern , i , pNdx ) == true ) { return true ; } } return false ; } } else { nextIsNotWildcard = false ; } if ( p != string . charAt ( sNdx ) ) { return false ; } sNdx ++ ; pNdx ++ ; } }
internal matching recursive function .
