RE2 (software)
This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages)
|
Original author(s) | |
---|---|
Initial release | March 11, 2010[1] |
Stable release | 2021-04-01
/ April 1, 2021[2] |
Repository | |
Written in | Cross-platform |
Type | Pattern matching library |
License | BSD |
Website | github |
RE2 is a software library for regular expressions via a finite-state machine using automata theory, in contrast to almost all other regular expression libraries, which use backtracking implementations. It provides a C++ interface.
RE2 was implemented and used by
Comparison to PCRE
RE2 generally compares to Perl Compatible Regular Expressions (PCRE) in performance. For certain regular expression operators like |
(logical disjunction or boolean "or") it exceeds PCRE. On the other hand, RE2 does not support back-references because the Thompson DFA[3] algorithm cannot implement those efficiently. It is also slightly slower than PCRE for parenthetic capturing operations.
PCRE can use a large
RE2 has a slightly smaller set of features than PCRE, but has very predictable run-time and a maximum memory allotment. This makes it suitable for use in server applications, which require boundaries on memory usage and computational time. PCRE, on the other hand, has almost all of the features that a regular expression library can have, but has unpredictable run-time and memory usage and can grow unbounded.
Adoption
Use in Google products
RE2 is, for example, used by
.In Google Sheets, it is used in the functions RegexMatch(), RegexReplace(), RegexExtract() and the find and replace feature. RegexExtract(), does not use grouping.
Related libraries
The RE2 algorithm has been rewritten in
Russ Cox also wrote RE1, an earlier regular expression based on a bytecode interpreter.[6] OpenResty uses a RE1 fork called "sregex".[7]
See also
References
- ^ Cox, Russ (March 11, 2010). "RE2: a principled approach to regular expression matching". Google Open Source Blog. Retrieved 2020-05-29.
- ^ "Releases". Github. Retrieved 2021-05-03.
- ^ a b Cox, Russ. "Regular Expression Matching in the Wild". swtch.com.
- ^ "Search and use find and replace". Retrieved 24 March 2020.
- ^ "Making the WAF 40% faster". The Cloudflare Blog. 1 July 2020.
- ^ "Regular Expression Matching: the Virtual Machine Approach". swtch.com.
- ^ "openresty/sregex: A non-backtracking NFA/DFA-based Perl-compatible regex engine matching on large data streams". OpenResty. 6 February 2024.