Ruby bindings to RE2, a fast, safe, thread-friendly alternative to backtracking regex engines like PCRE.
re2 is a Ruby gem that provides bindings to Google's RE2 regular expression engine. It offers a safer alternative to Ruby's built-in Regexp by eliminating regular expression denial of service (ReDoS) vulnerabilities through guaranteed linear-time matching and configurable memory limits. The library maintains a familiar API with RE2::Regexp and RE2::MatchData classes while providing thread-safe operation.
Ruby developers who need to process regular expressions from untrusted sources or require guaranteed performance bounds to prevent ReDoS attacks. Particularly valuable for web applications, security tools, and systems processing user-generated regex patterns.
Developers choose re2 over Ruby's built-in Regexp for its security guarantees against ReDoS attacks, thread-safe design, and predictable linear-time performance. It's the go-to solution when safety and reliability with regular expressions are more important than supporting every PCRE syntactic feature.
Ruby bindings to RE2, a "fast, safe, thread-friendly alternative to backtracking regular expression engines like those used in PCRE, Perl, and Python".
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Guarantees linear-time matching and configurable memory limits, preventing denial of service attacks from malicious regex patterns as highlighted in the README's safety focus.
Engine is built for safe concurrent use across multiple threads, addressing potential thread-safety issues in Ruby's regex, which is critical for multi-threaded applications.
Provides RE2::Regexp and RE2::MatchData classes with APIs similar to Ruby's built-in Regexp, easing adoption for developers, as shown in the usage examples.
RE2::Set allows simultaneous searching of multiple patterns, optimizing performance for batch operations like keyword filtering or logging analysis.
Sacrifices support for PCRE features like back-references and possessive quantifiers to ensure safety, restricting pattern complexity and compatibility with existing regex libraries.
Only supports UTF-8 and ISO-8859-1 encodings, requiring explicit conversion for other encodings, which adds overhead and potential for errors in internationalized applications.
Compiling from source requires a full C++ toolchain, CMake, and dependencies like Abseil, making setup non-trivial compared to pure-Ruby gems, especially on systems without native gems.