Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: counting overlapping patterns

by ikegami (Pope)
on Feb 18, 2005 at 21:46 UTC ( #432532=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://432532]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2019-11-18 06:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (87 votes). Check out past polls.

    Notices?