in reply to Calculating variable {n} in regex match
It sounds like the OP wants to capture the number of occurrences entirely within the regex, something like:
$foo =~ m/[0-9]({\d+})/ print "$foo has $1 digit(s)";
... if that were possible (it isn't). This would allow the counting match to be thrown in with a longer regex that is matching on other properties as well. This is probably possible through clever use of code evaluation (?{code}) and interpolation within the regex.
However, if all you need to do is count in the regex then you could use the 'goatse' operator:
my $length =()= $foo =~ /[0-9]/g; print "$foo has $length digit(s)";
Seems better than looping and incrementing, anyway.
Strange things are afoot at the Circle-K.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Calculating variable {n} in regex match
by AnomalousMonk (Archbishop) on Jun 05, 2012 at 19:49 UTC | |
by atreyu (Sexton) on Jun 14, 2012 at 14:02 UTC | |
by AnomalousMonk (Archbishop) on Jun 14, 2012 at 17:15 UTC | |
Re^2: Calculating variable {n} in regex match
by atreyu (Sexton) on Jun 05, 2012 at 18:03 UTC |
In Section
Seekers of Perl Wisdom