Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Testing regex equivalence

by loris (Hermit)
on Feb 21, 2006 at 13:13 UTC ( [id://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 . . ."

Replies are listed 'Best First'.
Re^3: Testing regex equivalence
by Corion (Patriarch) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://531684]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2024-04-24 23:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found