Skip to main content

fnmatch

Glob-style pattern matching. Used by glob, by command-line tools, and by anyone matching filenames without firing up a full regex.

Source-of-record: Lib/fnmatch.py, fnmatch docs.

Patterns

TokenMeaning
*Any sequence (no path separator in glob; any in fnmatch).
?One character.
[seq]One character in seq (ranges allowed).
[!seq]One character not in seq.

API

FunctionEffect
fnmatch(filename, pattern)Case-insensitive on case-insensitive FS, case-sensitive elsewhere.
fnmatchcase(filename, pattern)Always case-sensitive.
filter(names, pattern)Subset matching the pattern.
translate(pattern)Convert to a regex pattern string.

Gopy status

AreaState
All four functionsComplete.
translate output matches CPythonComplete; emits the same regex source.

Reference

  • CPython 3.14: fnmatch.
  • Lib/fnmatch.py.
  • module/fnmatch/. gopy port.