When I use a named regular expression, I can print its contents:
my regex rgx { \w\w };
my $string = 'abcd';
$string ~~ / <rgx> /;
say $<rgx>; # 「ab」
But if I want a match with an adverb :g
or :ex
, therefore, there is more than one match, it does not work. Following
my regex rgx { \w\w };
my $string = 'abcd';
$string ~~ m:g/ <rgx> /;
say $<rgx>; # incorrect
gives an error:
Type List does not support associative indexing.
in block <unit> at test1.p6 line 5
How do I change the code?
UPD: Based on the description of @piojo, I changed the last line as follows and solved my problem:
say $/[$_]<rgx> for ^$/.elems;
The following would be simpler, but for some reason it does not work:
say $_<verb> for $/; # incorrect
source
share