in reply to Re: Regex: continue from previous match
in thread Regex: continue from previous match

That's what I have (no \G) and it doesn't work. Your example of an 'a' followed by any one char will not match variable length or different ways at the same position, so it's moot. Put two a's in a row in your test string and you'll see overlapping matches.

 perl -E'while ("abaaxxxacxxad" =~ /a(.)/g) { say $& }'

Replies are listed 'Best First'.
Re^3: Regex: continue from previous match
by ikegami (Patriarch) on Apr 23, 2011 at 08:07 UTC

    Your example of an 'a' followed by any one char will not match variable length

    Sure it works with variable length patterns.

    while ('abxxxacdxxxae' =~ /a([^x]+)/g) { say $1; }

    Your example of an 'a' followed by any one char will not match [...] different ways at the same position

    Cause you didn't ask that. You asked about matching no earlier than pos.

    The only way to make the regex engine backtrack is to cause the match to fail.

    'abcd' =~ /(.*) (?{ say $1 }) (?!)/sx