Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Elegant (i.e. declarative) way to find all possibly overlapping matches (no dot)

by tye (Sage)
on Sep 18, 2003 at 14:16 UTC ( #292477=note: print w/replies, xml ) Need Help??


in reply to Elegant (i.e. declarative) way to find all possibly overlapping matches

Update: Just as I was about to post this, I figured out my own answer, using a lookahead: /(?=aa)./. The lookahead matches without advancing pos, the "." advances pos by 1. Are there other ways to do this? More efficient ways?

You don't need the dot:

my $str= "aaa aa aaa"; print "String = '$str'\n"; while( $str =~ /(?=aa)/g ) { print pos($str), $/; } __END__ String = 'aaa aa aaa' 0 1 4 7 8

See RE: Re: ^x* vs x*$ for why.

                - tye ("Twice in one day")
  • Comment on Re: Elegant (i.e. declarative) way to find all possibly overlapping matches (no dot)
  • Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2020-01-23 16:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?