@@ -1008,7 +1008,7 @@ The parentheses in regexes perform a double role: they group the regex
1008
1008
elements inside and they capture what is matched by the sub-regex inside.
1009
1009
1010
1010
To get only the grouping behavior, you can use square brackets C < [ ... ] >
1011
- instead .
1011
+ which, by default, don't capture .
1012
1012
1013
1013
if 'abc' ~~ / [a||b] (c) / {
1014
1014
say ~$0; # OUTPUT: «c»
@@ -1103,9 +1103,16 @@ and slightly verbose, way of naming captures is like this:
1103
1103
say ~$<myname> # OUTPUT: «abc»
1104
1104
}
1105
1105
1106
+ The square brackets in the above example, which don't usually capture, will now capture its grouping
1107
+ with the given name.
1108
+
1106
1109
The access to the named capture, C « $<myname> » , is a shorthand for indexing
1107
1110
the match object as a hash, in other words: C < $/{ 'myname' } > or C « $/<myname> » .
1108
1111
1112
+ We can also use round brackets in the above example, but they will work exactly the same as square brackets.
1113
+ The captured group will only be accessible by its name as a key from the match object and not from
1114
+ its position in the list with C < $/[0] > or C < $0 > .
1115
+
1109
1116
Named captures can also be nested using regular capture group syntax:
1110
1117
1111
1118
if 'abc-abc-abc' ~~ / $<string>=( [ $<part>=[abc] ]* % '-' ) / {
@@ -1129,7 +1136,7 @@ all named captures:
1129
1136
}
1130
1137
}
1131
1138
1132
- A more convenient way to get named captures is discussed in
1139
+ A more convenient way to get named captures is by using named regex as discussed in
1133
1140
the L < Subrules|#Subrules > section.
1134
1141
1135
1142
= head2 X « Capture markers: C « <( )> » |regex,<( )> »
0 commit comments