globmatch

2.0.0 · active · verified Thu Apr 16

globmatch provides functions for matching a path against one or more glob patterns in Python. Unlike the standard library's `glob` module, it does not interact with the filesystem, focusing solely on generic string matching. It extends `fnmatch` capabilities by supporting the `**` pattern for matching zero or more directories. The current version is 2.0.0, with releases historically being infrequent but demonstrating active maintenance.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic usage of `glob_match` with single and multiple patterns, including recursive matching with `**` and handling of dotfiles. The `match_all=True` parameter ensures all patterns are considered, enabling exclusion patterns.

from globmatch import glob_match

# Basic matching
print(glob_match('foo/config', ['**/config']))  # Expected: True
print(glob_match('foo/bar/config', ['**/config'])) # Expected: True
print(glob_match('foo/config/bar', ['foo/config'])) # Expected: False (needs /** for sub-elements)

# Matching dotfiles
print(glob_match('.git/gitconfig', ['.git/**'])) # Expected: True

# Multiple patterns
patterns = ['!.git', '**/config'] # Match config, but not if it's in .git
print(glob_match('.git/config', patterns, match_all=True)) # Expected: False
print(glob_match('myproject/config', patterns, match_all=True)) # Expected: True

view raw JSON →