def glob_to_re(pattern):
 pattern_re = fnmatch.translate(pattern)
 sep = os.sep
 if (os.sep == '\\'):
  sep = '\\\\\\\\'
 escaped = ('\\1[^%s]' % sep)
 pattern_re = re.sub('((?<!\\\\)(\\\\\\\\)*)\\.', escaped, pattern_re)
 return pattern_re

def glob_to_re ( pattern ) : pattern_re = fnmatch . translate ( pattern ) sep = os . sep if ( os . sep == '\\' ) : sep = '\\\\\\\\' escaped = ( '\\1[^%s]' % sep ) pattern_re = re . sub ( '((?<!\\\\)(\\\\\\\\)*)\\.' , escaped , pattern_re ) return pattern_re
translate a shell-like glob pattern to a regular expression; return a string containing the regex .