in reply to Re: Compare two regex patterns
in thread Compare two regex patterns
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.
|
|---|