def pathmatch(pattern, filename):
 symbols = {'?': '[^/]', '?/': '[^/]/', '*': '[^/]+', '*/': '[^/]+/', '**/': '(?:.+/)*?', '**': '(?:.+/)*?[^/]+'}
 buf = []
 for (idx, part) in enumerate(re.split('([?*]+/?)', pattern)):
  if (idx % 2):
   buf.append(symbols[part])
  elif part:
   buf.append(re.escape(part))
 match = re.match((''.join(buf) + '$'), filename.replace(os.sep, '/'))
 return (match is not None)

def pathmatch ( pattern , filename ) : symbols = { '?' : '[^/]' , '?/' : '[^/]/' , '*' : '[^/]+' , '*/' : '[^/]+/' , '**/' : '(?:.+/)*?' , '**' : '(?:.+/)*?[^/]+' } buf = [ ] for ( idx , part ) in enumerate ( re . split ( '([?*]+/?)' , pattern ) ) : if ( idx % 2 ) : buf . append ( symbols [ part ] ) elif part : buf . append ( re . escape ( part ) ) match = re . match ( ( '' . join ( buf ) + '$' ) , filename . replace ( os . sep , '/' ) ) return ( match is not None )
extended pathname pattern matching .