Jump to content

RE2 (software): Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Reverted 1 edit by Taxan2000 (talk) to last revision by Tedickey
Lairencha (talk | contribs)
m Punctuation
Line 32: Line 32:
PCRE can use a large [[recursion (computer science)#Other considerations|recursive stack]] with corresponding high memory use and have [[exponential time|exponential]] runtime on certain patterns. In contrast, RE2 uses a fixed stack and guarantees that run-time increases [[linear time|linearly]] (not exponentially) with the size of the input. The maximum memory allocated with RE2 is configurable.
PCRE can use a large [[recursion (computer science)#Other considerations|recursive stack]] with corresponding high memory use and have [[exponential time|exponential]] runtime on certain patterns. In contrast, RE2 uses a fixed stack and guarantees that run-time increases [[linear time|linearly]] (not exponentially) with the size of the input. The maximum memory allocated with RE2 is configurable.


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.
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.


==Use in Google products==
==Use in Google products==

Revision as of 13:25, 3 October 2023

RE2
Original author(s)Google
Initial releaseMarch 11, 2010; 14 years ago (2010-03-11)[1]
Stable release
2021-04-01 / April 1, 2021; 3 years ago (2021-04-01)[2]
Repository
Written inC++
Operating systemCross-platform
TypePattern matching library
LicenseBSD
Websitegithub.com/google/re2 Edit this at Wikidata

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 Google.

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 and cannot implement those efficiently. It is also slightly slower than PCRE for parenthetic capturing operations.

PCRE can use a large recursive stack with corresponding high memory use and have exponential runtime on certain patterns. In contrast, 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 is configurable.

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.

Use in Google products

RE2 is, for example, used by Google products like; Gmail, Google Documents and Google Sheets.[3] See GitHub for a documentation of the syntax: RE2 syntax.

In Google Sheets, it is used in the functions RegexMatch(), RegexReplace(), RegexExtract() and the find and replace feature. RegexExtract(), does not use grouping.

See also

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 2021-05-03.
  3. ^ "Search and use find and replace". Retrieved 24 March 2020.