pat_mc has asked for the wisdom of the Perl Monks concerning the following question:
As mentioned above, however, I would like to consolidate the information contained in the regex and the if statement into a single regex. It really should match if and only if the number of 'b's exceeds the number of 'a's in the string by one. I don't want any over-generation that I need to filter in a subsequent if statement.my @strings = qw( abb aabbb aaabbbb ab aab aabb abbb ); for ( @strings ) { our $a_counter = 0; our $b_counter = 0; if ( /(a(?{$a_counter ++;}))+(b(?{$b_counter ++;}))+/ && $b_counte +r == $a_counter + 1 ) { print "In '$_' there were $a_counter 'a's and $b_counter 'b's. +\n"; } }
|
---|