google-re2
RE2 Python bindings
What it is and what it does
google-re2 wraps Google's RE2 regular expression engine as a Python module that mimics the standard re module's interface. It trades support for some advanced PCRE features—like backreferences and lookaround assertions—for guaranteed linear-time matching and immunity to catastrophic backtracking, making it suitable for processing untrusted input or patterns where performance predictability matters.
The package is a compiled C++ extension, so installation uses prebuilt wheels when available. Its API closely mirrors Python's re module, but with notable differences: pattern and input strings don't need to match types (str is encoded to UTF-8), the Options class replaces re flags with RE2's own options, and error reporting is minimal. The description notes several syntax gotchas relative to Python's re—most notably that \Z must be rewritten as \z.
Use it for:
- Processing untrusted regex patterns or input where catastrophic backtracking is a security concern
- High-throughput text processing where predictable linear-time performance is required
- Migrating from re to a safer engine when PCRE features like backreferences are not needed
- Building systems that need consistent regex behavior across different input types without type coercion
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A drop-in replacement for Python's re module that uses Google's RE2 engine for pattern matching, trading some PCRE features for guaranteed linear-time performance.
Yes, if you need predictable regex performance and can accept RE2's syntax limitations. The permissive license and active repository are favorable. Medium install friction (system libraries required) and aging maintenance status (282 days since release) are minor concerns; the underlying RE2 engine is mature and the package has no known vulnerabilities. Not suitable if your patterns rely on backreferences, lookarounds, or other PCRE-only features.
Install
google-re2 on PyPI
pip
pip install google-re2uv
uv add google-re2poetry
poetry add google-re2Installing google-re2
Before you install
Medium install friction: precompiled wheels are available for current Python versions on macOS, Linux, and Windows, but building from source requires RE2 and pybind11 system libraries. The package is aging (282 days since last release) but the underlying repository remains active.
License in practice
Permissive license (BSD) means you can use, modify, and distribute this package with minimal restrictions, though you should include the license notice in distributions.
Quickstart
import re2
pattern = re2.compile(r'\w+')
match = pattern.search('hello world')
if match:
print(match.group())
Requires RE2 library and pybind11 to be installed on your system before installation; precompiled wheels available for Python 3.9+ on common platforms.
Verify before relying
- Performance characteristics compared to standard re module in typical workloads
- Compatibility with third-party libraries that expect the standard re module API
- Current status of Windows build support (documentation notes it has not been tested)
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (~=3.9) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | none |
| Maintenance | aging — 282 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 16,109,027/month — #1,161 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: google_re2-1.1.20251105-1-cp310-cp310-macosx_13_0_arm64.whl; google_re2-1.1.20251105-1-cp310-cp310-macosx_13_0_x86_64.whl; google_re2-1.1.20251105-1-cp310-cp310-macosx_14_0_arm64.whl; google_re2-1.1.20251105-1-cp310-cp310-macosx_14_0_x86_64.whl; google_re2-1.1.20251105-1-cp310-cp310-macosx_15_0_arm64.whl; google_re2-1.1.20251105-1-cp310-cp310-macosx_15_0_x86_64.whl; google_re2-1.1.20251105-1-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl; google_re2-1.1.20251105-1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl; google_re2-1.1.20251105-1-cp310-cp310-win32.whl; google_re2-1.1.20251105-1-cp310-cp310-win_amd64.whl; google_re2-1.1.20251105-1-cp311-cp311-macosx_13_0_arm64.whl; google_re2-1.1.20251105-1-cp311-cp311-macosx_13_0_x86_64.whl; google_re2-1.1.20251105-1-cp311-cp311-macosx_14_0_arm64.whl; google_re2-1.1.20251105-1-cp311-cp311-macosx_14_0_x86_64.whl; google_re2-1.1.20251105-1-cp311-cp311-macosx_15_0_arm64.whl; google_re2-1.1.20251105-1-cp311-cp311-macosx_15_0_x86_64.whl; google_re2-1.1.20251105-1-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl; google_re2-1.1.20251105-1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl; google_re2-1.1.20251105-1-cp311-cp311-win32.whl; google_re2-1.1.20251105-1-cp311-cp311-win_amd64.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
google-re2-stubsProvides type stubs for the google-re2 package,…
permissive · top 15,000 on PyPI
real-regexA drop-in replacement for Python's `re` module…
permissive · top 15,000 on PyPI
backrefsBackrefs extends Python's re and regex…
permissive · top 5,000 on PyPI
onigurumacffiProvides Python bindings to the Oniguruma regex…
permissive · top 15,000 on PyPI
re-assertProvides a helper class for regex assertions…
permissive · top 15,000 on PyPI
flpcflpc wraps the Rust regex crate to provide…
permissive · top 5,000 on PyPI
cel-pythonParses and evaluates Google Common Expression…
unclear · top 5,000 on PyPI
repathConverts Express-style path strings (like…
permissive · top 15,000 on PyPI