hound icon indicating copy to clipboard operation
hound copied to clipboard

Lookaround assertions in regular expressions?

Open cokelid opened this issue 7 years ago • 2 comments

If I write a regular expression with a (positive or negative) lookahead (or lookbehind) assertion I get an error saying it's incorrect Perl syntax.

For example to look for the text "function" that's not followed by an underscore, I might use this: function(?!_)

However that returns the error: ERROR:error parsing regexp: invalid or unsupported Perl syntax: (?!

However they do work in Perl!

Any ideas?

PS: In this toy example I could use a negated character class function[^_] for searching, but I'm interested in the general case rather than a solution to a specific pattern.

cokelid avatar Feb 19 '19 09:02 cokelid

OK, looks like this is a limitation with regex in Go (RE2), rather than a Perl thing:

https://github.com/golang/go/issues/18868 https://github.com/google/re2/issues/156

cokelid avatar Feb 19 '19 09:02 cokelid

If there are errors, it may be worthwhile to show a link to some documentation alongside the parsing error. We'd love a PR for that contribution.

salemhilal avatar May 27 '20 18:05 salemhilal