Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re^3: Why machine-generated solutions will never cease to amaze me

by tmoertel (Chaplain)
on Nov 11, 2004 at 16:18 UTC ( #407092=note: print w/replies, xml ) Need Help??

in reply to Re^2: Why machine-generated solutions will never cease to amaze me
in thread Why machine-generated solutions will never cease to amaze me

hv wrote:
Regexp union is not commutative when one of the alternates is a leading substring of another: then order becomes important - (E|x) will always match E in preference to x.
Excellent point. (However, union is commutative even in the face of overlapping operands when the union is forced to match all of the target string or not match at all.)
It is the presence of the outer anchors in the original pattern that disambiguates and thus makes (regexp union) commutative.
Even anchoring isn't sufficient. What if one of the anchors matches the difference between the union operands? Consider (a|aa) in:
"aaaa" =~ /a(a|aa)a/

Fortunately, in the case of the OP's regexes – s(?:al|pre)?ad and s(?:(?:al)?|pre)ad) – the union operands don't overlap, and so classical equivalence (do the regexps generate the same language?) predicts the equivalence of Perl's matching behavior (do the regexps match the same strings identically?)


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://407092]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2016-12-09 21:45 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (157 votes). Check out past polls.