RE2 (software)
≈ 2 min read
Names in other languages
No names in other languages are held for this entry yet.
Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.
RE2 is a C++ software library which implements a regular expression engine . It uses finite-state machines, in contrast to most other regular expression libraries. RE2 requires a minimum C++ version of C++17, and uses the Abseil library by Google. RE2 was implemented by Google and Google uses RE2 for Google products. RE2 uses an "on-the-fly" deterministic finite-state automaton algorithm based on Ken Thompson's Plan 9 grep. It is designed to avoid ReDoS (regex denial of service) attacks.
RE2 is a C++ software library which implements a regular expression engine . It uses finite-state machines, in contrast to most other regular expression libraries. RE2 requires a minimum C++ version of C++17, and uses the Abseil library by Google. RE2 was implemented by Google and Google uses RE2 for Google products. RE2 uses an "on-the-fly" deterministic finite-state automaton algorithm based on Ken Thompson's Plan 9 grep. It is designed to avoid ReDoS (regex denial of service) attacks. import ; import std; using std::string; using re2::RE2; int main(int argc, char* argv[]) { string text = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!" string pattern = "(a+)+$"; bool match = RE2::FullMatch(text, pattern); std::println("Match result: {}", match); }
Related libraries
RE2 comes with a built-in Python wrapper, available on Python Package Index (PyPI) as google-re2 . The built-in regexp package in Go uses the same patterns and implementation as RE2, though it is written in Go. This is unsurprising, given Go's common staff from the Plan 9 team. The RE2 algorithm has been rewritten in Rust as the package regex . CloudFlare's web application firewall uses this package because the RE2 algorithm is immune to ReDoS. Russ Cox also wrote RE1, an earlier regular expression based on a bytecode interpreter. OpenResty uses a RE1 fork called "sregex". There is an official Java binding, called RE2J ( com.google.re2j ). The following languages have unofficial bindings: C (cre2) D (re2d) Erlang (re2) Inferno (inferno-re2) JavaScript (RE2JS), a port of RE2J to JavaScript Node.js (node-re2) OCaml (re2) Perl (re-engine-RE2) R (re2) Ruby (re2) WebAssembly (re2-wasm)
See also
Comparison of regular expression engines
References
Text derived from https://en.wikipedia.org/w/index.php?oldid=1368386410 under CC BY-SA 4.0; modifications have been made.