RE2 (software)

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
Original author(s)Google
Initial releaseMarch 11, 2010 (2010-03-11)[1]
Stable release
2020-05-01 / May 1, 2020 (2020-05-01)[2]
Repository
Written inC++
Operating systemCross-platform
TypePattern matching library
LicenseBSD
Websitegithub.com/google/re2

RE2 was implemented and is used by Google.

Comparison to PCRE

"RE2" compares to Perl Compatible Regular Expressions (PCRE) in performance, but greatly exceeds PCRE for regular expression operators like | (logical disjunction or boolean "or").

RE2 does not support back-references, which cannot be implemented efficiently. It is also slightly slower than PCRE for parenthetic capturing operations, but is much faster for matching in general.

PCRE can use a large recursive stack and have exponential runtime on certain patterns. RE2 uses a fixed stack and guarantees that run-time increases linearly (not exponentially) with the size of the input. The maximum memory allocated with RE2 can be configured if you have good knowledge of the workings of its code.

Google's RE2 has a slightly smaller set of features than PCRE, but has very predictable run-time and a maximum memory allotment, making it suitable for use in server applications which require precise 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.

RE2 by Google is designed for the Linux operating system. It also runs on MS Windows using MSVC, MinGW, or Cygwin. It should also run on other operating systems that support CMake.

Use of RE2 in Google products

Some Google products use RE2, like Gmail, Google Documents and Google Sheets[3].

RE2 syntax

Google Sheets

Re2 is used in Google Sheets in RegexMatch(), RegexReplace(), RegexExtract() functions and find and replace feature.

RegexExtract() does not use grouping.

gollark: It's a terrible solution.
gollark: They have a superintelligent AI! I'm sure it can deal with it!
gollark: And the scythe organization is horrific and ridiculous too, see.
gollark: Unwanted death is still bad! Especially when they can just not have it!
gollark: Many people have already been convinced that death is good somehow.

See also

  • Comparison of regular expression engines

References

  1. Cox, Russ (March 11, 2010). "RE2: a principled approach to regular expression matching". Google Open Source Blog. Retrieved 2020-05-29.
  2. "Releases". Github. Retrieved 2020-05-29.
  3. "Search and use find and replace". Retrieved 24 March 2020.
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.