in reply to Controlling matching position in regexes to match all proper substrings

There is a anchor symbol to define where the search has to continue.

IIRC it's \G, so /(a\Ga)/g should do.

Have a look at perlre and perlretut .

update

Otherwise pos can be used in a while loop to read and set the next search start position.

Just subtract the length of your pattern from pos and add 1 to continue.

Cheers Rolf

(addicted to the Perl Programming Language and ☆☆☆☆ :)

  • Comment on Re: Controlling matching position in regexes to match all proper substrings
  • Download Code

Replies are listed 'Best First'.
Re^2: Controlling matching position in regexes to match all proper substrings
by LanX (Saint) on Oct 04, 2014 at 14:25 UTC
    I'm now at a box which runs Perl and can test:

    \G doesn't help, forgot about the limitations!¹

    But the pos approach works:

    DB<129> $_='12aaa67aaaa23' => "12aaa67aaaa23" DB<130> print pos($_) while ($_=~/(a\Ga)/g) DB<131> print pos($_),"\n" and pos($_)=pos($_)-1 while ($_=~/(aa)/g) 4 5 9 10 11

    HTH! :)

    Cheers Rolf

    (addicted to the Perl Programming Language and ☆☆☆☆ :)

    ¹) perlretut : the \G anchor is only fully supported when used to anchor to the start of the pattern.