google/re2

Created Dec 22, 2020 · View the google/re2 repository page

RE2 is a fast, safe, thread-friendly alternative to backtracking regular expression engines like those used in PCRE, Perl, and Python. It is a C++ library.

Want this for your repo?

Render a free sample of any GitHub repo in seconds.

Visualize your own →

Contributors

54

Lines of Code

2,320

From

Mar 3, 2010

To

Nov 26, 2020

About google/re2

RE2 is a fast, safe, and thread-friendly regular expression library written in C++ that has been used in production at Google since 2006. Unlike traditional backtracking engines such as those in PCRE, Perl, and Python, RE2 prioritizes safety and predictable performance as its core design goals. The library guarantees that match time is linear in the length of the input string, making it suitable for processing regular expressions from untrusted sources without risk of catastrophic performance degradation.

The library achieves its safety guarantees by avoiding constructs that require backtracking, such as backreferences and lookaround assertions. Instead, RE2 evaluates alternatives in parallel, which incurs some overhead but prevents exponential runtime behavior. It supports both POSIX and Perl regex syntax modes, with comprehensive configuration options for customization. The implementation includes built-in memory and stack budgets that fail gracefully when exhausted, addressing production concerns about resource consumption.

RE2 is written in C++17 and depends on the Abseil library, building via Make, CMake, or Bazel. An official Python wrapper is available on PyPI as google-re2, and numerous community ports exist for languages including Node.js, Ruby, Go, Rust, Java, and WebAssembly. The project maintains an active issue tracker and mailing list for community engagement, with a documented contribution process that uses the issue tracker rather than pull requests.

Share this video

More from google

See all →