The thing I've mainly used named captures for so far is named access to the capture groups via %+. This can be very useful e.g. in cases like long regexes and/or if you've got one qr// regex inside another qr// regex inside another... keeping track of numbered capture groups quickly becomes impossible.
my $one = qr{ one (?<one> \d+ ) }xi; my $two = qr{ $one two (?<two> \d+ ) }xi; "One9Two8Three7" =~ m{ $two three (?<three> \d+ ) }xi; use Data::Dump; dd \%+; __END__ { # tied Tie::Hash::NamedCapture one => 9, three => 7, two => 8, }
One bigger example that comes to my mind is this one: if you happen to have a 4th edition Camel (not sure if it's in the earlier ones), have a look at Chapter 5, Section "Fancy Patterns", subsection "Grammatical Patterns". You can basically build entire grammars out of them, for example using (?&NAME) you can recurse to a named subpatten (perlre; Update: a shorter example can be found under the documentation of (DEFINE)). Whether you want to build a full grammar using Perl's regex engine instead of one of the many well-established modules is of course another question :-)
Update 2: It seems I misread the question "What is the prevalent name for this feature" as "What is the prevalent use for this feature".
Update: Used /x and brackets to make the regexes more readable, eliminating a typo in the process. Changed the order of the paragraphs. Updated wording a little bit.
In reply to Re: Parameterized Regex (updated)
by haukex
in thread Parameterized Regex
by QM
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |