Good commentary AnomalousMonk :)

This is where something like rxrx shines over use re 'debug'; as it shows you how the matching goes without the interference of optimizations :)

Restarting regex match | V /(?=4)W/ | V '54w' [Visual of regex at 'rxrx' line 0] [step: 0] --- Starting positive lookahead | VVV /(?=4)W/ | V '54w' [Visual of regex at 'rxrx' line 0] [step: 1] --- Trying a literal '4' character | V /(?=4)W/ | V '54w' [Visual of regex at 'rxrx' line 0] [step: 2] --- Failed | V /(?=4)W/ | V '54w' [Visual of regex at 'rxrx' line 0] [step: 3] --- Back-tracked within regex and rerestarting regex match | V /(?=4)W/ | V '54w' [Visual of regex at 'rxrx' line 0] [step: 4] --- Starting positive lookahead | VVV /(?=4)W/ | V '54w' [Visual of regex at 'rxrx' line 0] [step: 5] --- Trying a literal '4' character | V /(?=4)W/ | V '54w' [Visual of regex at 'rxrx' line 0] [step: 6] --- Matched | V /(?=4)W/ | V '54w' ^ [Visual of regex at 'rxrx' line 0] [step: 7] --- Back-tracked within regex and reend of positive lookahead | V /(?=4)W/ |< V '54w' [Visual of regex at 'rxrx' line 0] [step: 8] --- Trying a literal 'W' character | V /(?=4)W/ | V '54w' [Visual of regex at 'rxrx' line 0] [step: 9] --- Failed | V /(?=4)W/ | V '54w' [Visual of regex at 'rxrx' line 0] [step: 10] --- Back-tracked within regex and rerestarting regex match | V /(?=4)W/ | V '54w' [Visual of regex at 'rxrx' line 0] [step: 11] --- Starting positive lookahead | VVV /(?=4)W/ | V '54w' [Visual of regex at 'rxrx' line 0] [step: 12] --- Trying a literal '4' character | V /(?=4)W/ | V '54w' [Visual of regex at 'rxrx' line 0] [step: 13] --- Failed | V /(?=4)W/ | V '54w' [Visual of regex at 'rxrx' line 0] [step: 14] --- Back-tracked within regex and rerestarting regex match | V /(?=4)W/ | V '54w' [Visual of regex at 'rxrx' line 0] [step: 15] --- Starting positive lookahead | VVV /(?=4)W/ | V '54w' [Visual of regex at 'rxrx' line 0] [step: 16] --- Trying a literal '4' character | V /(?=4)W/ | V '54w' [Visual of regex at 'rxrx' line 0] [step: 17] --- Regex failed to match after 18 steps | V /(?=4)W/ | V '54w' [Visual of regex at 'rxrx' line 0] [step: 18] ---

So hopefully you can see from rxrx output that zero-width assertions match from current position without advancing that pos()ition . "Look-behind matches text up to the current match position, look-ahead matches text following the current match position." The position is pos() an is advanced by matching patterns

So in the OPs , pos(0) tries to see ahead if '5' is 4 which its not, the bumps pos(1) and tries to see ahead if '4' is 4 and it is , but then it fails to match a W at pos(1) , because the look-ahead didn't advance pos()ition, and there is a 4 at pos(1) and not a W ..... :)


In reply to Re^2: zero-width assertions for extended regular expressions (rxrx) by Anonymous Monk
in thread zero-width assertions for extended regular expressions by johnrcomeau

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.