On this page
fnmatch.translate
Prev: fnmatch.fnmatchcase | Up: fnmatch
Rel: fnmatch.filter, fnmatch.filterfalse, fnmatch.fnmatch, fnmatch.fnmatchcase
Ref: docs.python.org — fnmatch.translate
Tags: #public #python3 #stdlib #fnmatch
Import
import fnmatch
from fnmatch import translate
Signature & Overview
fnmatch.translate(pat)
Translate a shell PATTERN to a regular expression.
Usage
import fnmatch
import re
regex = fnmatch.translate("*.py")
assert re.match(regex, "main.py") is not None
Gotchas
- Converts a shell-style glob to a regex string: Note
*matches/too (it does not treat path separators specially).
REPL Inspect
from fnmatch import translate
help(translate)
Linked from
Related notes
- tuts/python3/stdlib_module/fnmatch/filter Linked here; links to this page; shared tags: #fnmatch, #stdlib
- tuts/python3/stdlib_module/fnmatch/filterfalse Linked here; links to this page; shared tags: #fnmatch, #stdlib
- tuts/python3/stdlib_module/fnmatch/fnmatch Linked here; links to this page; shared tags: #fnmatch, #stdlib
- tuts/python3/stdlib_module/fnmatch/fnmatchcase Linked here; links to this page; shared tags: #fnmatch, #stdlib
- tuts/python3/stdlib_module/fnmatch links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib
- tuts/c/stdlib/assert/static_assert shared tags: #stdlib
- tuts/c/stdlib/ctype shared tags: #stdlib