in reply to Re: zero-width assertions for extended regular expressions
in thread zero-width assertions for extended regular expressions

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 ..... :)