skillfed

multiregex

Quickly match many regexes against a string. Provides 2-10x speedups over naïve regex matching.

multiregex v2.0.4 79.3K downloads/30d#14,364 on PyPI38
Permissive license BSD-3-Clause Active released

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 multiregex

uv

uv add multiregex

poetry

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 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

Programming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.9

Tags

match multiple regexes at oncefast bulk regex matchingregex performance optimizationbatch pattern matchingprematcher regex accelerationefficient multi-pattern searchregex speedup library
regex-optimizationpattern-matchingperformance

More Text Processing packages