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-re2Verified import paths — ran on the pinned version, not inferred.
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.
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.
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.
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.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.
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 `(?!,)`.
First, ensure the package is installed using `pip install google-re2`. Then, import it correctly in your Python code using `import re2`.
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`.
No dependency data recorded yet.