RE2 (software)
RE2 is a software library which implements a regular expression engine. It uses finite-state machines, in contrast to most other regular expression libraries. RE2 supports a C++ interface. RE2 was implemented by Google and Google uses RE2 for Google products.[3] RE2 uses an "on-the-fly" deterministic finite-state automaton algorithm based on Ken Thompson's Plan 9 grep.[4] Comparison to PCRERE2 performs comparably to Perl Compatible Regular Expressions (PCRE). For certain regular expression operators like 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. AdoptionUse in Google productsRE2 is available to users of Google Docs and Google Sheets.[5] Google Sheets supports RE2 except Unicode character class matching.[6] RegexExtract does not use grouping. Use in GoThe built-in "regexp" package uses the same patterns and implementation as RE2, though it is written in Go.[7] This is unsurprising, given Go's common staff from the Plan 9 team. Related librariesThe 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.[8] Russ Cox also wrote RE1, an earlier regular expression based on a bytecode interpreter.[9] OpenResty uses a RE1 fork called "sregex".[10] See alsoReferences
|