Skip to content

Declaring named capture groups #25

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
elfring opened this issue Oct 9, 2021 · 11 comments
Closed

Declaring named capture groups #25

elfring opened this issue Oct 9, 2021 · 11 comments

Comments

@elfring
Copy link

elfring commented Oct 9, 2021

Named capture groups are supported for a while.
How do you think about a software extension for the possibility to declare the binding of regular expressions to identifiers before such identifiers would be reused at other places?

@zherczeg
Copy link
Collaborator

zherczeg commented Oct 9, 2021

You can use (DEFINE) or (?:){0} blocks to define named blocks after a pattern, and you can append your "library" after a pattern with string concatenation.

@elfring
Copy link
Author

elfring commented Oct 9, 2021

I would appreciate improved descriptions for the mentioned functionality according to desirable pattern definitions.

@elfring
Copy link
Author

elfring commented Oct 9, 2021

  • May patterns be declared or defined in multiple lines?
  • Would any extra white-space characters influence subsequent pattern matching in undesirable ways?

@zherczeg
Copy link
Collaborator

With /x, (?x:), PCRE2_EXTENDED you can ignore spaces in the pattern, and even comments can be added. Inside (DEFINE), or (?:){0} everything is ignored. The only way to use something inside a (DEFINE) is recursion.

@PhilipHazel
Copy link
Collaborator

Take a look at the file testdata/testinput1 in the PCRE2 distribution. Search for the string "BNF". There you will find some complicated patterns that use (DEFINE) to transliterate BNF syntax descriptions more or less directly into named patterns groups.

@elfring
Copy link
Author

elfring commented Oct 10, 2021

Thanks for your link to another provided test case.

🔮 How will the chances evolve to improve the documentation any further also for this software area?

@PhilipHazel
Copy link
Collaborator

I have fixed that minor typo, thanks for noticing. I think this issue is now done.

@elfring
Copy link
Author

elfring commented Oct 29, 2021

💭 I would appreciate further documentation extensions for pattern definition groups.

@PhilipHazel
Copy link
Collaborator

PCRE2 documentation is not really the place for tutorials. For discussion of (?(DEFINE) see this web site:

https://www.regular-expressions.info/subroutine.html

@elfring
Copy link
Author

elfring commented Oct 30, 2021

PCRE2 documentation is not really the place for tutorials.

💭 I hope that this information source can become better and more complete (also in comparison to the other good information source which you mentioned).

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