in reply to Re: •Re: Regex - unordered lookaround syntax
in thread Regex - unordered lookaround syntax

But have you ever stopped to wonder why you don't get an infinite loop at the first empty space? (This is explained in perlre, but virtually nobody understands the explanation.)
  • Comment on Re: Re: •Re: Regex - unordered lookaround syntax

Replies are listed 'Best First'.
Re: Re: Re: •Re: Regex - unordered lookaround syntax
by halley (Prior) on Apr 29, 2003 at 15:31 UTC

    When you have a /g (or the /g-like looping implied by split()), the matcher tries again and again to find more matches. To avoid such infinite loops, the engine advances pos() by one character if the pattern didn't already define any advancement. This goes for empty patterns like // as well as some combination of zero-width assertions like /(?=f\w\w)(?!foo)/. The /gc variety can control this somewhat.

    The "Mastering Regular Expressions" book likes to call this the 'bump along' effect: the 'transmission' bumps along the text until the pattern can succeed, or proven to fail.

    --
    [ e d @ h a l l e y . c c ]