Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Compare two regex patterns

by zer (Deacon)
on Mar 06, 2008 at 06:27 UTC ( #672377=note: print w/replies, xml ) Need Help??

in reply to Compare two regex patterns

from the looks of it, a good solution may be to use Regexp::Optimizer on both values. Then see if they are equal after

Replies are listed 'Best First'.
Re^2: Compare two regex patterns
by ikegami (Patriarch) on Mar 06, 2008 at 15:38 UTC

    That doesn't work for two reasons.

    1. Regexp::Optimizer is a no-op if no alternation is used.

    2. Even if Regexp::Optimizer normalized regexps, the normalized regexps still wouldn't be equal since the two regexps are not equivalent.

    use Regexp::Optimizer qw( ); my $o = Regexp::Optimizer->new(); print $o->optimize(qr/123*/), "\n"; # (?-xism:123*) print $o->optimize(qr/1233*/), "\n"; # (?-xism:1233*) print $o->optimize(qr/123+/), "\n"; # (?-xism:123+)

    The OP didn't ask for a method to check if two regexp are equivalent, but for a method to check if a regexp will match at least everything a second regexp matches.

    Update: Added code. Changed formatting.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2022-08-17 20:16 GMT
Find Nodes?
    Voting Booth?

    No recent polls found