in reply to counting overlapping patterns
The key is to match without consuming text. The following works.
It'll go through it repeatedly, starting at each position, but never consuming anything.while("AAAA" =~ /(?=AA)/g){ $count++; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: counting overlapping patterns
by ikegami (Patriarch) on Feb 18, 2005 at 21:46 UTC | |
by Eimi Metamorphoumai (Deacon) on Feb 18, 2005 at 22:15 UTC | |
by ikegami (Patriarch) on Feb 18, 2005 at 23:39 UTC |
In Section
Seekers of Perl Wisdom