RE2 is a C++ library that provides a fast, safe, and thread-friendly regular expression engine.
Traditional backtracking regex engines like those in PCRE, Perl, and Python can suffer from catastrophic backtracking, where certain patterns cause exponential time complexity and potential denial-of-service vulnerabilities. RE2 solves this by using finite automata instead of backtracking, guaranteeing linear time matching regardless of input or pattern complexity. This approach trades some features—notably backreferences and lookahead assertions—for predictable performance and safety.
Developers should choose RE2 when working in C++ and prioritizing performance guarantees and thread safety over regex feature completeness. It suits systems where untrusted regex patterns might be supplied by users, where matching latency must be bounded, or where regex operations run in concurrent environments. Projects that require backreferences or advanced assertions will need to accept the limitations or use a different engine.
The project maintains a steady stream of commits addressing bug fixes and incremental improvements. Pull requests receive thoughtful review with discussion of design tradeoffs and edge cases. The maintainers respond to issues with technical depth, often explaining the reasoning behind design decisions and the constraints imposed by the finite automata approach. Documentation is thorough, including detailed explanations of what features are unsupported and why.