I'm matching a sequence of a repeating arbitrary character, with a minimum length, using a perl6 regex.
After reading through https://docs.perl6.org/language/regexes#Capture_numbers and tweaking the example given, I've come up with this code using an 'external variable':
#uses an additional variable $c
perl6 -e '$_="bbaaaaawer"; /((.){} :my $c=$0; ($c)**2..*)/ && print $0';
#Output: aaaaa
To aid in illustrating my question only, a similar regex in perl5:
#No additional variable needed
perl -e ' $_="bbaaaaawer"; /((.)2{2,})/ && print $1';
Could someone enlighten me on the need/benefit of 'saving' $0
into $c
and the requirement of the empty {}
? Is there an alternative (better/golfed) perl6 regex that will match?
Thanks in advance.
See Question&Answers more detail:os