Regexp::Compare - partial ordering for regular expressions


Regexp-Compare documentation Contained in the Regexp-Compare distribution.

Index


Code Index:

NAME

Top

Regexp::Compare - partial ordering for regular expressions

SYNOPSIS

Top

  use Regexp::Compare qw(is_less_or_equal);

  if (is_less_or_equal($rx[i], $rx[j])) {
      print "duplicate: $rx[i]\n";
  }

DESCRIPTION

Top

This module implements a function comparing regular expressions: it returns true if all strings matched by the first regexp are also matched by the second. It's meant to be used for optimization of blacklists implemented by regular expressions (like, for example, http://www.communitywiki.org/cw/BannedContent ).

Both arguments of is_less_or_equal are strings - IOW the call

  $rv = is_less_or_equal($rx, /hardcoded/i);

probably won't do what you want - use

  $rv = is_less_or_equal($rx, '(?i:hardcoded)');

instead.

False return value does not imply that there's a string matched by the first regexp which isn't matched by the second - many regular expressions (i.e. those containing Perl code) are impossible to compare, and this module doesn't even implement all possible comparisons.

BUGS

Top

* comparison fails for locale-specific constructs
* comparison fails for regexps with backreferences
* global variables affecting regexp matching are ignored

AUTHOR

Top

Vaclav Barta, <vbar@comp.cz>

COPYRIGHT AND LICENSE

Top

SEE ALSO

Top

Rx


Regexp-Compare documentation Contained in the Regexp-Compare distribution.

package Regexp::Compare;

require 5.008_006;
use strict;
use warnings;

require Exporter;

our @ISA = qw(Exporter);

our @EXPORT_OK = qw(is_less_or_equal);
our @EXPORT = qw();

our $VERSION = '0.14';

require XSLoader;
XSLoader::load('Regexp::Compare', $VERSION);

sub is_less_or_equal {
    local ${^RE_TRIE_MAXBUF} = -1;
    return Regexp::Compare::_is_less_or_equal(@_);
}

1;
__END__