-
Notifications
You must be signed in to change notification settings - Fork 49
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
Request: (?(DEFINE)...) #152
Comments
Original comment by Matthew Barnett (Bitbucket: mrabarnett, GitHub: mrabarnett). In your webpages you give a workaround for implementations that don't support it:
There's a shorter alternative:
|
Original comment by Matthew Barnett (Bitbucket: mrabarnett, GitHub: mrabarnett). Added in regex 2015.09.14. |
Original comment by boolbag NA (Bitbucket: boolbag, GitHub: boolbag). Wow, that is awesome, thank you so much!!! And thank you also for the "shorter workaround tip" two posts up. I've already "advertised" the new features on the StackOverflow regex chat room, where many regex heads hang out. :) Will also go update my pages to mention that this is now supported. I've been meaning for some time to do a real tut on your engine (at the time I first mentioned it, I wasn't doing much Python.) Need to make the time for this. Here is a short example for anyone who would like to see the feature at work:
|
I can't get the above example to work with Python 3.11 and latest regex package.
None |
@asarkar: Try |
@5j9
|
I'm not entirely sure why |
Calling a subroutine is not the same as capturing, even though a subroutine is defined as a group. Other regex implementations that support subroutines behave the same, except in Ruby, I've read. If you want to capture, define a separate capture group.
|
It appears that in #296 I decided that Should it change? |
🤷🏻 I'll say I found it confusing is all. I assumed if |
Based on the comments in the tickets I've linked to earlier, it seems most users expect groups to be not |
I guess if it were me, I'd either commit to them being capture groups or commit to them not being capture groups. I think either way seems reasonable to me, but half capture, but not really seems odd and unintuitive. At least that is my personal feelings. If the idea is to model the majority of implementations, then not being a capture group makes the most sense. |
Original report by boolbag NA (Bitbucket: boolbag, GitHub: boolbag).
Hi again Matthew,
This is the second in a series of posts to present a case for three features.
In this post, I'll focus on
(?(DEFINE)...)
When crafting long expressions with repeated components, I find the
(?(DEFINE)...)
syntax immensely valuable. It is the key to writing modular regex. Some time ago I presented an example to show the value of such a modular regex here.(?(DEFINE)...)
allows you to drop short names in the pattern. These names expand to large sub-expressions. When sub-expressions are repeated in multiple places in the pattern, this lets you keep your sanity, because you don't have to change the pattern in multiple places.I came up with a workaround that I explained here some time ago. Nevertheless, for compatibility with PCRE and Perl when translating large expressions, it would be wonderful to have the same
(?(DEFINE)...)
syntax inregex
.Thanks in advance for considering it.
The text was updated successfully, but these errors were encountered: