Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Precise backreference semantics in Perl regular expressions

by hv (Prior)
on Nov 09, 2023 at 16:44 UTC ( [id://11155515]=note: print w/replies, xml ) Need Help??


in reply to Precise backreference semantics in Perl regular expressions

The main question is whether \2 should have a value at all when that alternate failed to match last time through the alternation.

See the recent bug report Perl #21563. There is definite inconsistency in how backreferences are preserved or discarded when backtracking, but it is unclear what consistent behaviour we should be aiming at.

Based on the expectation I (hvds) described in that issue ("... that we would retain only results from the last successful match, so that ((a)|(b))+ would never return captures of both a and b") with which demerphq agreed, neither of your strings should match - after we match the /a*b?d/ alternate, \2 from the other alternate should be unset.

I hope that at some point we will settle on the principle of how it should behave, and document that clearly; I don't think we're there yet. I would not, however, expect to see extensive comparisons with other regexp engines in Perl's documentation: there are too many moving targets involved. I think I remember that PCRE documentation had more of such comparisons though.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2024-05-21 16:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found