multiregex
Quickly match many regexes against a string. Provides 2-10x speedups over naïve regex matching.
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 on this page — 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
multiregex on PyPI
pip
pip install multiregexuv
uv add multiregexpoetry
poetry add multiregexInstalling 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 the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — pyahocorasick |
| Maintenance | actively maintained — 86 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 79,338/month — #14,364 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: multiregex-2.0.4-py3-none-any.whl
Tags
More Text Processing packages
A drop-in replacement for Python's standard…
permissive · top 100 on PyPI
pyparsingpyparsing provides a library for building text…
permissive · top 1,000 on PyPI
docutilsDocutils converts plaintext documentation in…
unclear · top 1,000 on PyPI
RapidFuzzRapidFuzz provides fast fuzzy string matching…
permissive · top 1,000 on PyPI
tinycss2tinycss2 parses CSS strings into token and…
permissive · top 1,000 on PyPI
llama-parseLlamaParse parses complex documents (PDFs,…
permissive · top 1,000 on PyPI
retrieBuilds efficient Trie-based regex patterns for…
permissive · top 15,000 on PyPI
rebulkReBulk provides a fluent API for building…
permissive · top 15,000 on PyPI
tfidf-matcherPerforms fast fuzzy string matching on large…
permissive · top 15,000 on PyPI
interegularInteregular checks whether pairs of Python…
permissive · top 5,000 on PyPI
ahocorasick-rsSearches for multiple substrings in text or…
permissive · top 15,000 on PyPI
textsearchFind and replace multiple strings in text with…
permissive · top 15,000 on PyPI
regexploitRegexploit analyzes regular expressions to…
permissive · top 15,000 on PyPI
real-regexA drop-in replacement for Python's `re` module…
permissive · top 15,000 on PyPI
hyperscanPython bindings for Vectorscan (an open-source…
permissive · top 15,000 on PyPI
ttpTTP is a Python library for parsing…
permissive · top 15,000 on PyPI