Live data from Hacker News

Adding lookbehinds to rust-lang/regex

systemf.epfl.ch

31–36 of 36 posts

Re: Adding lookbehinds to rust-lang/regex

#31

From a user perspective, this is extremely valuable. What an amazing improvement; unbounded especially. I do hope this would make it into actual RE2 & go. When I use regex, I expect to be able to lookbehind, so I am routinely hit by RE2's limitations in places where it's used. Sometimes the software uses the entire matched string and you can't use non-capturing groups to work around it. I understand go's reasons, ReD…

> I understand go's reasons, ReDoS etc, but the "purism" of RE2 does fly in the face of practicality to an irksome degree.

Preventing ReDos is literally the reason RE2 exists though, so I don't think it's "purism" to not implement these things. What you want is not unreasonable, but fundamentally incompatible with the goals of RE2.

Ways to do look-behinds in linear time, as detailed in this article, are a relatively new development AFAIK(?) I don't think the RE2 people are principally opposed to integrating that if it can be done well. I suspect someone will have to write a patch though, since the main RE2 maintainer died last year.

Re: Adding lookbehinds to rust-lang/regex

#32

Earlier quoted context omitted.

As others have pointed out, the regex engine is the same so the benefits would trickle downstream. For example, VSCode also uses ripgrep and therefore the rust-lang/regex engine.

ripgrep plugged this gap a long time ago by providing PCRE2 support.

PCRE2 supports only bounded length lookbehinds. It is true, it is not a big improvement to have unbounded ones in rust-lang/regex, but it still feels like something.

Re: Adding lookbehinds to rust-lang/regex

#33

Earlier quoted context omitted.

so Rust has no regex in the standard library, basic/fast regex under the rust-lang umbrella in a crate and fancy-regex is a 3rd party crate not having different options is the point of (batteries included) standard libraries ;-)

We (I am on libs-api in addition to authoring the regex crate) specifically eschewed a batteries included standard library. The fact that `regex` was its own thing was the best thing that ever happened to it. It let me iterate on its API independent of the standard library.

fair enough - there are pros and cons, but in many situations that _can_ lead to balkanisation of the language

Raku has specifically chosen the "kitchen sink" option with a massive amount of cool stuff included ... I would argue that have both regex and Grammars tightly in the core language syntax is a big win in that case (and the default choice of Str as graphemes)

with Rust and Raku that's mitigated by crate and zef respectively - both reliable, unified package manager ecosystems

Re: Adding lookbehinds to rust-lang/regex

#34
post #27

Earlier quoted context omitted.

The authors’ previous article (linked in this one) was about doing this in re2 ( https://systemf.epfl.ch/blog/re2-lookbehinds/ ), and they have a fork with those changes though I don’t know that they have a PR. > the "purism" of RE2 does fly in the face of practicality to an irksome degree It’s not purism tho. There are very practical reasons to want an FA-based engine, and if you compromise that to get additional fe…

I couldn't find the link in that page, but the fork is here, and seems to be up-to-date: https://github.com/GerHobbelt/re2 If you need that from Go, you can probably use that to create a fork of this: https://github.com/wasilibs/go-re2

The RE2 fork from the blog post above is this one: https://github.com/epfl-systemf/re2-lookbehinds

Re: Adding lookbehinds to rust-lang/regex

#35

Earlier quoted context omitted.

ripgrep plugged this gap a long time ago by providing PCRE2 support.

PCRE2 supports only bounded length lookbehinds. It is true, it is not a big improvement to have unbounded ones in rust-lang/regex, but it still feels like something.

Pretty minor IMO. And PCRE2 supports lots of other stuff beside look-behinds.

Re: Adding lookbehinds to rust-lang/regex

#36
post #34
post #27

Earlier quoted context omitted.

I couldn't find the link in that page, but the fork is here, and seems to be up-to-date: https://github.com/GerHobbelt/re2 If you need that from Go, you can probably use that to create a fork of this: https://github.com/wasilibs/go-re2

The RE2 fork from the blog post above is this one: https://github.com/epfl-systemf/re2-lookbehinds

Thank you! I had searched GitHub by a relevant snippet of code described in the blog and found that one. I guess they merged those changes?
Post reply on HN