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

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 . . ."

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 voices are still...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2017-12-16 11:18 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (450 votes). Check out past polls.