in reply to Re: counting overlapping patterns
in thread counting overlapping patterns

Alternatively,

while ('AAAA' =~ /A(?=A)/g) { $count++; }

which looks slightly less weird to me.

Replies are listed 'Best First'.
Re^3: counting overlapping patterns
by Eimi Metamorphoumai (Deacon) on Feb 18, 2005 at 22:15 UTC
    But requires rewriting the pattern. Mine will work even if the pattern comes from a variable, or contains different possibilities for the first character ('/AA|BB/' becomes '/(?=AA|BB)/'). My approach was to try to do minimal tinkering with the original, but yeah, it's not as obvious what's actually going on.
      Good point.