--- id: multiregex version: "2.0.4" license: BSD-3-Clause license_treatment: permissive maintenance: active --- # multiregex — Quickly match many regexes against a string. Provides 2-10x speedups over naïve regex matching. License: permissive · Maintenance: active · Downloads: 79.3K/mo ## What it is and what it does multiregex is a pattern-matching library that accelerates searching for multiple regex patterns in a single string. Instead of running each regex independently, it uses "prematchers"—fast substring checks that predict whether a full regex is likely to match—to skip expensive regex evaluation on non-matching candidates. The library provides three matching modes (search, match, fullmatch) that mirror Python's standard re module, returning sets of (Pattern, Match) tuples for all patterns that matched. The speedup comes from filtering: prematchers are lists of literal strings that must be present if a regex matches, so multiregex checks for these substrings first and only evaluates the full regex on promising candidates. For simple patterns like r"\w+\.com", prematchers are generated automatically; for complex patterns, you supply your own or disable prematching entirely. The library includes a profiler to measure prematcher effectiveness and identify false positives. Use it for: - Scan log files or text streams for multiple error/warning patterns without running each regex separately - Extract multiple entity types (emails, URLs, phone numbers) from documents in a single pass - Validate input against a ruleset of regex constraints where most rules will not match most inputs - Build content filters that check text against many blocked-pattern rules efficiently - Implement multi-pattern search in text editors or code analysis tools ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Matches multiple regex patterns against a string efficiently by using prematchers to filter candidates before full regex evaluation, delivering 2-10x speedups over naïve regex matching. Yes. Low install friction, active maintenance, no security issues, and a clear performance win for the specific problem it solves (matching many regexes). The permissive BSD-3-Clause license poses no restrictions. Worth installing if you routinely match multiple patterns against strings; not necessary for single-pattern matching or if your patterns are already optimized. ## Install pip install multiregex uv add multiregex poetry add multiregex ## Installing multiregex Before you install: Low friction: pure Python wheel with a single runtime dependency (pyahocorasick). Active maintenance with recent commits and no known vulnerabilities. License in practice: BSD-3-Clause (permissive) allows commercial and private use with minimal restrictions; attribution required. Quickstart: import multiregex my_patterns = [r"\w+@\w+\.com", r"\w\.com"] matcher = multiregex.RegexMatcher(my_patterns) results = matcher.search("john.doe@example.com") # Returns list of (re.Pattern, re.Match) tuples Requires Python 3.9 or later. Complex regex patterns may require manual prematcher configuration to avoid ValueError. Verify before relying: - Whether the 2-10x speedup range applies to typical production workloads or only specific pattern/text combinations - Performance characteristics when matching against very large numbers of patterns (hundreds or thousands) ## Package facts - License: BSD-3-Clause (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 79.3K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags match multiple regexes at once, fast bulk regex matching, regex performance optimization, batch pattern matching, prematcher regex acceleration, efficient multi-pattern search, regex speedup library, regex-optimization, pattern-matching, performance [View on SkillFed](https://skillfed.io/packages/multiregex) · [View on PyPI](https://pypi.org/project/multiregex/)