Registry / serialization / google-re2

google-re2

JSON →
library1.1.20251105pypypi✓ verified 24d ago

google-re2 provides Python bindings for Google's high-performance RE2 C++ regular expression library. It offers a fast and secure alternative to Python's built-in `re` module, designed for linear-time execution, but with a more restricted feature set. The library maintains a frequent release cadence, often monthly, reflecting updates to the underlying C++ library.

pip install google-re2
INSTALL
IMPORT
SIG · GOOGLE-RE2
G
google-re2
serializationpythonv1.1.20251105
Install
1.6s avg
Import
Disk
17MB
Pass rate
4/ 10
Env Coverage4 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.1.20251105 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
✓ 1.6s
py 3.11
✕ build_error
✓ 1.7s
py 3.12
✕ build_error
✓ 1.5s
py 3.13
✕ build_error
✓ 1.5s
py 3.9
✕ build_error
✕ build_error
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

re2
import re2
import google_re2
The PyPI package `google-re2` exposes its functionality via the `re2` module name.

This example demonstrates basic usage of the `re2` module, including compiling patterns, searching, finding all matches, and performing substitutions. The API largely mirrors Python's built-in `re` module for common operations.

import re2 # Compile a regex pattern pattern = re2.compile(r'hello (\w+)') # Search for a match match = pattern.search('hello world') if match: print(f"Found: {match.group(0)}") print(f"Captured: {match.group(1)}") # Find all occurrences text = 'hello python, hello universe' all_matches = re2.findall(r'hello (\w+)', text) print(f"All matches: {all_matches}") # Replace text replaced_text = re2.sub(r'hello', 'hi', text) print(f"Replaced text: {replaced_text}")
Debug
Known issues
gotcha`re2` is NOT a full drop-in replacement for Python's `re` module. It intentionally omits advanced features like backreferences, lookarounds, and some complex Unicode properties for performance and security reasons. Patterns using these features will raise `re2.error: invalid perl_re`.
fix
Review and rewrite regex patterns to avoid unsupported features. Consult RE2's C++ syntax documentation for supported features. For patterns requiring full PCRE compatibility, consider `re` or `regex` libraries.
affects: All versions
gotchaInstallation may require a C++ compiler (e.g., GCC, Clang, MSVC) and RE2 C++ library headers if pre-built wheels are not available for your specific Python version and operating system. This can complicate deployment in environments without build tools.
fix
Ensure your environment has a C++ compiler and the necessary RE2 C++ development files. On Debian/Ubuntu: `sudo apt-get install build-essential libre2-dev`. On Fedora: `sudo dnf install @development-tools re2-devel`. On Windows, install Visual C++ Build Tools.
affects: All versions
gotchaWhile `re2` supports UTF-8, its interpretation of certain character classes (e.g., `\b` for word boundaries, `\w` for word characters) can differ from Python's `re` module, especially with non-ASCII or complex Unicode text. This can lead to unexpected matching behavior.
fix
Thoroughly test patterns with diverse Unicode inputs. Explicitly use Unicode character properties (e.g., `\p{L}` for letters) where supported if fine-grained Unicode control is needed.
affects: All versions
Errors
Common errors & fixes
ERROR: Failed building wheel for google-re2
This error commonly occurs during installation due to missing C++ development tools (like a C++ compiler or the `libre2-dev` package) or `pybind11`, or environment-specific issues, particularly on macOS where Xcode Command Line Tools might be outdated or absent.
fix
Ensure that required system dependencies are installed (e.g., `sudo apt-get install libre2-dev pybind11-dev` on Debian/Ubuntu, or ensure Xcode Command Line Tools are updated on macOS) and install `pybind11` via `pip install pybind11`. Consider using a clean Python virtual environment.
re2.error: invalid perl operator: (?!)
The RE2 library has a more restricted feature set than PCRE or Python's built-in `re` module; it does not support advanced regular expression features like lookarounds (e.g., positive/negative lookahead `(?=...)`, `(?!...)`, or lookbehind `(?<=...)`, `(?<!...)`) or backreferences.
fix
Rewrite the regular expression to avoid unsupported features by using alternative patterns or string manipulation before or after the regex match. For example, `(?:$|[^,])` can often replace `(?!,)`.
ModuleNotFoundError: No module named 're2'
This error occurs when the `google-re2` package has not been installed, or it was installed but imported with an incorrect module name. The package is imported as `re2`, not `google_re2` or similar variations.
fix
First, ensure the package is installed using `pip install google-re2`. Then, import it correctly in your Python code using `import re2`.
NameError: basestring
This error indicates an incompatibility issue, typically arising when an older version of the `re2` Python binding or a binding designed for Python 2 is being used in a Python 3 environment. `basestring` was a built-in type in Python 2 that was removed in Python 3.
fix
Ensure you have the `google-re2` package (or a Python 3 compatible `pyre2` binding) installed for your current Python 3 environment, and upgrade it to the latest version using `pip install --upgrade google-re2`.
Upgrade
Version history
1.1.20251105latest on PyPI · released Nov 5, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Resources
google-re2 — pip install google-re2 · libregistry