in reply to Capturing with look-ahead

Capture two chars inside the lookahead and throw in another dot afterwards to advance one character in the string:

$_ = 'blah'; my @matches = /(?=(..))./g; print "@matches\n";

Replies are listed 'Best First'.
Re: Re: Capturing with look-ahead
by japhy (Canon) on Mar 04, 2002 at 21:02 UTC
    The extra . isn't necessary, although I have a feeling it makes the regex more efficient.

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a (from-home) job
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

      Why is that? (?=) is zero-width, why does it look further one char next time?
        I direct your attention to perlre, the section named Repeated patterns matching zero-length substring. This complicated section can be summarized by this extract: "the following match after a zero-length match is prohibited to have a length of zero."

        _____________________________________________________
        Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a (from-home) job
        s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;