in reply to Integrating match counts into regex matching
I agree with tilly and Not_a_Number about keeping it simple but...
I find the following easier to understand. Of the alternatives I have seen for putting everything in the RE I find the following easier to understand.
m[ ^ (a*) (??{ 'b' x ( length($1) + 1 ) }) $ ]x and print "'$_'\n" for qw[ ab abb abbb aabb aabbb aabbbb xaabbby ]; 'abb' 'aabbb'
Update: I mean easier to understand than the alternatives that have been proposed for putting everything into the RE, not easier to understand than separating the condition. I would do it as Not_a_Number suggested myself.
Update: Note that this solution is only correct for strings matching the pattern /^a+b+$/ and decides differently than the test in the original post for many of the broader set of strings matching /a+b+/ (e.g. "ababb", "babbb", "acabbb" and many others. It can only be made more correct by making it much more complicated, so really not worth pursuing.
|
|---|