http://www.perlmonks.org?node_id=432501


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

$count++ while $string =~ /\GAA/gc;
Er, no, the \G there serves no purpose as that's the default behaviour anyway. On this other hand this will work, by only consuming the first character of the match:
$count++ while $string =~ /A(?=A)/g;

Dave.

Replies are listed 'Best First'.
Re^3: counting overlapping patterns
by Anonymous Monk on Feb 18, 2005 at 20:34 UTC
    Dave you truly are "the m". That works as promised. Thanks!