Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re^2: Testing regex equivalence

by loris (Hermit)
on Feb 21, 2006 at 13:13 UTC ( #531684=note: print w/ replies, xml ) Need Help??

in reply to Re: Testing regex equivalence
in thread Testing regex equivalence

What I want to do is really to parse the regex in some way and simplifiy it, if possible. So say I have a regex generator and for a certain input it produces


I would like to be able to recognise that this is the same as




"It took Loris ten minutes to eat a satsuma . . . twenty minutes to get from one end of his branch to the other . . . and an hour to scratch his bottom. But Slow Loris didn't care. He had a secret . . ."

Comment on Re^2: Testing regex equivalence
Select or Download Code
Replies are listed 'Best First'.
Re^3: Testing regex equivalence
by Corion (Pope) on Feb 21, 2006 at 13:19 UTC

    They aren't strictly equivalent, because the first regex has capturing parentheses even if they only will ever match the empty string at the end of the string. But assuming you have

    /(?:.*).*$/ # and /.*$/

    you could convert them into canonical form, that is, normalize all .* to become (?:.*), and then simplify, mapping (?:.*)(?:.*) to (?:.*).

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2015-11-26 23:30 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (709 votes), past polls