Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lookaround assertions in regular expressions? #305

Open
cokelid opened this issue Feb 19, 2019 · 2 comments
Open

Lookaround assertions in regular expressions? #305

cokelid opened this issue Feb 19, 2019 · 2 comments

Comments

@cokelid
Copy link

cokelid commented Feb 19, 2019

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
Copy link
Author

cokelid commented Feb 19, 2019

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

golang/go#18868
google/re2#156

@salemhilal
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants