Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating backreferences from a repeating group

Tags:

regex

(?:\/(\w+?=\/)\/(\w+))*

Is there any way to retrieve backreferences from within a group? In my expression above does the no-reference (?:) prevent the entire group from capturing backreferences?

Trying to match for example: /hello/how/are/you.../today and capture all the values between '/'

like image 936
Magic Lasso Avatar asked Aug 15 '26 04:08

Magic Lasso


1 Answers

Is there any way to retrieve backreferences from within a group?

Yes. Groups are not interpreted in a hierarchy. For example (a(b)) has simply two groups, one and two, which can be (back)referenced. In terms of references it is equal to (a)(b). The order of the references is simply determined by the order of the groups (determined by the start of the group) in the regex pattern. The fact that one group is part of another group does not change this fact.

In my expression above does the no-reference (?:) prevent the entire group from capturing backreferences?

No. It only prevents the group marked as a non capture group from capturing (back)references. Nested groups are unaffected and will be captured unless they, too, are marked as non capture groups.

like image 139
Lodewijk Bogaards Avatar answered Aug 19 '26 17:08

Lodewijk Bogaards



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!