in reply to Integrating match counts into regex matching

If that is what you want, then that is what you want. But the cure is worse than the disease.
/^(?>(?:a(?{ $count-- })|b(?{ $count++ }))+)(??{ $count==1 ? "" : "a" })\z/
Don't forget to have a local our $count; in front of that. And don't forget to buy a bullet-proof vest in case the maintenance programmer ever tracks you down.

Replies are listed 'Best First'.
Re^2: Integrating match counts into regex matching
by pat_mc (Pilgrim) on Dec 18, 2008 at 23:57 UTC
    Phew, tilly -

    This looks like a tricky one. Not sure I fully decipher it but I venture a transcript of your code here: "If the regex matches an 'a', decrease $count, if it matches a 'b', increase $count. Repeat as long as you can. When all the matching is done, check the value of $count. If it is '1' return the empty string, else return 'a'. Is this anywhere near the truth?

    Also not sure what the \z does.

    Thanks for your help though!

    Cheers - Pat
      That is correct. The \z means end of string. It keeps you from matching things like "ben".

      But I misread your problem. I will match things like "bab" which is not according to your spec.