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