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/lookbehind regex that used to work not working anymore #6265

Closed
Artturin opened this issue May 11, 2023 · 6 comments
Closed

lookaround/lookbehind regex that used to work not working anymore #6265

Artturin opened this issue May 11, 2023 · 6 comments
Labels

Comments

@Artturin
Copy link
Contributor

Artturin commented May 11, 2023

Describe the bug

Error: Failed to compile the regex pattern: "(?<=got.....)sha256.{45}" with error: error parsing regexp: invalid or unsupported Perl syntax: `(?<`

To Reproduce
Steps to reproduce the behavior:

  1. run echo "got: sha256-L8wivKxb5OWfbnU/7Rs6GzecDLOCxAsukoO2Qj7egfU=" | kitten hints --program @ --type regex --regex '(?<=got.....)sha256.{45}'
  2. See error

https://regex101.com/r/ieCHXq/1 shows that it should work with PCRE/2, if golang is chosen from the flavors then it fails so it looks like its not supported in go regexp :(

kitty 5b8b91b

@Artturin Artturin added the bug label May 11, 2023
@kovidgoyal
Copy link
Owner

The regex engine was changed to the one native to Go which doesnt
support these for performance reasons, IIRC.

@kovidgoyal
Copy link
Owner

Note that go has a regexp2 library that supports these, it should be a relatively simply patch to use that instead of the stdlib one to add support. I dont have much motivation for this, but PR is welcome.

@kovidgoyal
Copy link
Owner

You can also use the custom processing to do your matching in python using the python regex engine, without needing any patches.

@kovidgoyal
Copy link
Owner

Actually in your case you dont need the look behind at all. If the regex contains a single unnamed group the match will be just that groups contents. So you can use

got.*?sha256(.{45})

@Artturin
Copy link
Contributor Author

Actually in your case you dont need the look behind at all. If the regex contains a single unnamed group the match will be just that groups contents. So you can use

got.*?sha256(.{45})

correct regex would be
got.*?(sha256.{45})

@Artturin
Copy link
Contributor Author

Thanks for 65f8bb7.

You're awesome and one of the best open source developers!

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

No branches or pull requests

2 participants