Translate a shell PATTERN to a regular expression. There is no way to quote meta-characters.
>>> import fnmatch, re >>> >>> regex = fnmatch.translate('*.txt') >>> regex '(?s:.*\\.txt)\\z' >>> reobj = re.compile(regex) >>> reobj.prefixmatch('foobar.txt') <re.Match object; span=(0, 10), match='foobar.txt'>
fnmatch/translate
translate