Questions tagged [re2]

RE2 is a fast, safe, thread-friendly alternative to backtracking regular expression engines like those used in PCRE, Perl, Python and Go. It is a C++ library.

RE2 is a fast, safe, thread-friendly alternative to backtracking regular expression engines like those used in PCRE, Perl, Python and Go. It is a C++ library, released under the BSD License.

Backtracking engines are typically full of features and convenient syntactic sugar but can be forced into taking exponential amounts of time on even small inputs. RE2 uses automata theory to guarantee that regular expression searches run in time linear in the size of the input. RE2 implements memory limits, so that searches can be constrained to a fixed amount of memory. RE2 is engineered to use a small fixed C++ stack footprint no matter what inputs or regular expressions it must process; thus RE2 is useful in multithreaded environments where thread stacks cannot grow arbitrarily large.

When RE2 was released, Russ Cox the main author of RE2, published a series of articles on the CS theory and real world implementation of regular expressions. Including some in depth benchmarks of RE2 vs competing regex libraries.

Bindings for some scripting languages languages exist for Python and Ruby.

Supported syntax can be found here.

382 questions
50
votes
4 answers

Split string and get last element

Let's say I have a column which has values like: foo/bar chunky/bacon/flavor /baz/quz/qux/bax I.e. a variable number of strings separated by /. In another column I want to get the last element from each of these strings, after they have been split…
Max Williams
  • 32,435
  • 31
  • 130
  • 197
39
votes
3 answers

Do RE2-like regular expression library for Java exist?

Did anyone come across Java version of Google's regular expression library RE2 or a java library with similar capabilities and good performance? The performance requirement is linear time with regard to the length of regular expression and the input…
depthofreality
  • 579
  • 6
  • 14
23
votes
8 answers

Multiple regex matches in Google Sheets formula

I'm trying to get the list of all digits preceding a hyphen in a given string (let's say in cell A1), using a Google Sheets regex formula : =REGEXEXTRACT(A1, "\d-") My problem is that it only returns the first match... how can I get all…
flo5783
  • 697
  • 2
  • 6
  • 19
22
votes
5 answers

Is it possible to use re2 from Python?

i just discovered http://code.google.com/p/re2, a promising library that uses a long-neglected way (Thompson NFA) to implement a regular expression engine that can be orders of magnitudes faster than the available engines of awk, Perl, or Python. so…
flow
  • 3,624
  • 36
  • 48
20
votes
3 answers

Using positive-lookahead (?=regex) with re2

Since I'm a bit new with re2, I'm trying to figure out how to use positive-lookahead (?=regex) like JS, C++ or any PCRE style in Go. Here's some examples of what I'm looking for. JS: 'foo bar…
a8m
  • 9,334
  • 4
  • 37
  • 40
15
votes
1 answer

Why is std::regex notoriously much slower than other regular expression libraries?

This Github repository added std::regex to the list of regular expression engines and got decimated by the others. Why is that std::regex - as implemented in libstdc++ - so much slower than others? Is that because of the C++ standard requirements or…
user8143588
15
votes
5 answers

How to build Google RE2 for Windows?

How to build Google RE2 for Windows? Somebody tried?
user536232
  • 645
  • 5
  • 18
12
votes
2 answers

Regular Expression Tester for Google RE2

I'm looking for a regular expression tester for Google Big Data (RE2) reg expressions. There are a few testers out there, but none of them seems to understand my statement. These are the ones I've tried and they've worked for simple expressions but…
devnull
  • 131
  • 1
  • 1
  • 5
10
votes
1 answer

Understanding xfuncname by git diff

I would like to know how exactly git diff applies the expression provided to xfuncname to the result and if it is possible to delegate the search for the hunk header text to another program. Context: I would like to change the xfuncname setting for…
Talon
  • 1,775
  • 1
  • 7
  • 15
10
votes
2 answers

Negate match in RE2 syntax?

How can I write a regex in RE2 for "match strings not starting with 4 or 5"? In PCRE I'd use ^(?!4) but RE2 doesn't support that syntax.
Richard
  • 62,943
  • 126
  • 334
  • 542
9
votes
3 answers

How to screen double quotes in Google Docs re2 expressions?

I'm trying to screen double quotes in regular expression on Google Sheets and there's no luck. A1 cell text = some "name" My formula =REGEXEXTRACT(A1;"\"(.*)\"") But Google Docs thinks that i'm using quotes for open /close argument. Please…
Evgeny Malkov
  • 437
  • 1
  • 5
  • 18
8
votes
3 answers

How can I normalize / asciify Unicode characters in Google Sheets?

I'm trying to write a formula for Google Sheets which will convert Unicode characters with diacritics to their plain ASCII equivalents. I see that Google uses RE2 in its "REGEXREPLACE" function. And I see that RE2 offers Unicode character classes. I…
Kirkman14
  • 1,506
  • 4
  • 16
  • 30
7
votes
1 answer

How do I find the offset of a matching string using RE2?

RE2 is a modern regular expression engine available from Google. I want to use RE2 in a program that is currently using gnuregex. The problem I have relates to finding out what matched. What RE2 returns is the string that matched. I need to know the…
vy32
  • 28,461
  • 37
  • 122
  • 246
6
votes
2 answers

Regex "NOT" in Google Sheets (RE2)

I want to check if in a cell there is one word but not another. In this post there was some buzz around this matter but the elected solution included a script function. There has to be an easier way to do that. I want to check if in the string…
aabujamra
  • 4,494
  • 13
  • 51
  • 101
6
votes
4 answers

Updating Gitlab from 9.3.7 to 9.3.8 getting Error installing re2

We are running on Ubuntu 14.04, with Gitlab 9.3.7, which works fine. We are trying to update to the latest security patch of Gitlab v9.3.8, but it gives us this error: Gem::Ext::BuildError: ERROR: Failed to build gem native extension. current…
Out of Control
  • 456
  • 1
  • 6
  • 21
1
2 3
25 26