Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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 web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2020-10-25 09:16 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (249 votes). Check out past polls.