Skip to content

Discovering which capture groups are required to match, from a compiled regexp ? #204

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

Closed
chetmurthy opened this issue Feb 6, 2023 · 3 comments

Comments

@chetmurthy
Copy link

I'm writing helper wrappers based on the OCaml Pcre library, and one of the things that would be useful is the ability to learn for each capture group whether, if the regexp matches, the capture group will match. I don't see any entrypoint for doing this, and truthfully I don't know enough about PCRE's regexp language to know whether it's even computable, but for simpler regexp languages it seems pretty straightforward.

I thought I'd ask here if this were something that's possible with Pcre.

@zherczeg
Copy link
Collaborator

zherczeg commented Feb 7, 2023

I think it is computable. But generic pattern analysis in not a pcre thing, there are other projects for that:
https://github.com/zherczeg/repan

@PhilipHazel
Copy link
Collaborator

I would have thought, for any sensible regex, that any capture group might match - otherwise what is the point of having the capture group in the regex? Of course, one can write patterns with groups that can never match - a trivial example is /(*FAIL)(group)/ - but clearly such patterns are not useful. Or are you wanting to analyze patterns to check whether there are any unreachable groups? As Zoltan says, pattern analysis is not something PCRE goes in for. In any case, this is a general discussion rather than an issue (IMHO). There's a Google group for PCRE2 discussions.

@chetmurthy
Copy link
Author

an example of such a regexp would be: (a)(b)?(c)- groups 1,3 MUST match, for the entire regexp to match, but group 2 MAY match.

I didn't realize there was a Google group for PCRE discussions; I'll go there, thanks!

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

No branches or pull requests

3 participants