Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^3: Variable-Width Lookbehind (hacked via recursion)

by haukex (Archbishop)
on Oct 30, 2017 at 17:20 UTC ( [id://1202346]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Variable-Width Lookbehind (hacked via recursion)
in thread Variable-Width Lookbehind (hacked via recursion)

putting the explanation of why into words...

So the two key things to note are:

  • The pattern (?<!X) (for any character X) matches at the beginning of the string (because there is no preceding character), and
  • the double negation of (?<! (?! ) ) means that whatever the inner call to (?&lookback) returns (match/no match) is what the outer (?<lookback> ) will return. So what the last, innermost (furthest left) lookback returns is what the whole, outermost lookback will return.

So for the regex in question it boils down to two cases:

  • If there is no preceding "a", then the regex will recurse all the way to the beginning of the string, where lookback will match.
  • If there is a preceding "a", then (?<!a) will cause the match to fail.

Minor edit for clarification.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1202346]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-19 22:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found