in reply to Re^3: How can I access the number of repititions in a regex?
in thread How can I access the number of repititions in a regex?

Oh yes, I am.

Consider this:
while ( <> ) { print $a_counter, $b_counter if /a+b+/; }


with an input like "aaabb" I would expect an output like
3 2

Know what I mean?

Thanks again for taking the time to comment. Your help is much appreciated!

Replies are listed 'Best First'.
Re^5: How can I access the number of repititions in a regex?
by driver8 (Scribe) on Mar 14, 2008 at 01:13 UTC
    It sounds like you want something like this:
    for ('aabbbbbc', 'abccc', 'aabcc', 'aaacccc', 'abc') { print length $1, length $2, length $3, "\n" if /(a+)(b+)(c+)/; }
    Though I never would have guessed that's what you were looking for from your initial post. If that doesn't do it, maybe you should post some of the actual data your dealing with and your expected output. -driver8
      Good idea, driver8 -

      The only limitation of this solution being that it only works for match strings of length 1. Also, the result of the number of matches is only available outside the regex.

      What I would like to have is a regex that can extract something like "give me all matches containing one more 'b' than 'a's".

      abb matches
      aabbb matches
      aabb does not match

      I think we need a code evaluation expression to solve this, so something along the lines suggested by grizley below.

      Thanks for your input!

      Cheers -

      Pat