in reply to pos CONFUSION in REGEX

You regexes matches with length zero at position 1, so after the first match pos is set to 1.

Then the regex engine tries again starting from point 1, and matches again. Since it matched with zero width twice in a row, the regex engine fears an infinite recursion and artificially bumps the position.

Most patterns don't have side effects, so usually you don't observe this behaviour - but it's the reason why split // works (unless that case is special-cased).

Perl 6 - links to (nearly) everything that is Perl 6.

Replies are listed 'Best First'.
Re^2: pos CONFUSION in REGEX
by suhailck (Friar) on Dec 14, 2009 at 16:47 UTC
    Thanq moritz
    and Anonymous Monk for your advice to use code tag :)