Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

.*

Thanks,

loris


"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
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2014-09-02 05:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (20 votes), past polls