MarketRE2 (software)
Company Profile

RE2 (software)

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.

Comparison to PCRE
RE2 performs comparably to Perl Compatible Regular Expressions (PCRE). For certain regular expression operators like | (the operator for alternation or logical disjunction) it is superior to PCRE. Unlike PCRE, which supports features such as lookarounds, backreferences and recursion, RE2 is only able to recognize regular languages due to its construction using the Thompson DFA algorithm. It is also slightly slower than PCRE for parenthetic capturing operations. PCRE can use a large recursive stack with corresponding high memory usage and result in exponential runtime on certain patterns. In contrast, RE2 uses a fixed stack size and guarantees that its runtime increases linearly (not exponentially) with the size of the input. The maximum memory allocated with RE2 is configurable. This can make it more suitable for use in server applications, which require boundaries on memory usage and computational time. == Adoption ==
Adoption
RE2 is available to users of Google Docs and Google Sheets. Google Sheets supports RE2 except Unicode character class matching. RegexExtract does not use grouping. == Example ==
Example
Here is an example of using re2 against a potential ReDoS (regular expression denial of service) attack. 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==
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==
tickerdossier.comtickerdossier.substack.com