globre

raw JSON →
0.1.5 verified Fri May 01 auth: no python maintenance

A glob matching library providing an interface similar to the `re` module. Version 0.1.5 is latest. The library appears to be in maintenance mode with infrequent releases.

pip install globre
error AttributeError: module 'globre' has no attribute 'compile'
cause globre does not implement a compile() function; it provides match, search, etc. directly.
fix
Use globre.match(pattern, string) directly; no compile step needed.
error SyntaxError: invalid syntax (when using '**' in pattern)
cause User mistakenly used '**' in a context where Python interprets it as exponentiation (e.g., inside an f-string or without quotes).
fix
Always pass patterns as strings: globre.match('**/*.py', 'src/mod.py')
gotcha Common mistake: treat globre.match() like Python's fnmatch. globre.match() behaves like re.match (anchored at start) but with glob syntax. To match anywhere use globre.search().
fix Use globre.search() for partial matches, globre.match() for anchored start.
gotcha Pattern syntax: globre uses standard glob patterns (like **, *, ?, [...]) not regex. Escaping special regex characters is not needed, but glob special characters must be escaped. This confusion often leads to errors.
fix Remember: it's glob syntax, not regex. Use bracket patterns like [abc] for character sets, * for any string, ? for single char.

Basic usage: import globre and use match() like re.match().

import globre
# Match a glob pattern
if globre.match('*.py', 'test.py'):
    print('matches')