logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Regexp::Optimizer - optimizes regular expressions

Acknowledgements

Author

       Dan Kogai, "<dankogai+cpan at gmail.com>"

Bugs

       Please report any bugs or feature requests to "bug-regexp-optimizer at rt.cpan.org", or through the web
       interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Regexp-Optimizer>.  I will be notified, and
       then you'll automatically be notified of progress on your bug as I make changes.

Caveat

??{CODE}used
       This module depends on the "??{CODE}" regexp construct which is still considered experimental as of Perl
       5.16.

   notidempotent
       If you feed the regexp that is already optimized, the resulting regexp may not necessarily the same --
       usually you get duplicate "(?:)":

           my $re = qr/foobar|fooxar|foozap/;
           $re = $ro->optimize($re); # qr/foo(?:[bx]ar|zap)/
           $re = $ro->optimize($re); # qr/foo(?:(?:[bx]ar|zap))/

Export

       none.

Name

       Regexp::Optimizer - optimizes regular expressions

See Also

       Regexp::Assemble, perlre

Subroutines/Methods

new
       Makes a new optimizer instance.

         my $ro = Regexp::Optimizer->new;

   optimize
       Does the optimization.

         my $re = qr/foobar|fooxar|foozap/;
         $re = $ro->optimize($re);

       If it is already optimized -- no alteration in the regexp, it is practically an identity function which
       simply returns an argument.

       If not, it dissasembles the regexp, feeds it to Regexp::Assemble, and reassembles the result.

   as_string
       Same as "optimize()" but returns a string instead of regexp object.

Support

       You can find documentation for this module with the perldoc command.

           perldoc Regexp::Optimizer

       You can also look for information at:

       •   RT: CPAN's request tracker (report bugs here)

           <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Regexp-Optimizer>

       •   AnnoCPAN: Annotated CPAN documentation

           <http://annocpan.org/dist/Regexp-Optimizer>

       •   CPAN Ratings

           <http://cpanratings.perl.org/d/Regexp-Optimizer>

       •   Search CPAN

           <http://search.cpan.org/dist/Regexp-Optimizer/>

Synopsis

         use Regexp::Optimizer;
         my $o  = Regexp::Optimizer->new->optimize(qr/foobar|fooxar|foozap/);
         # $re is now qr/foo(?:[bx]ar|zap)/

Version

       $Id: Optimizer.pm,v 0.23 2013/02/26 05:47:41 dankogai Exp dankogai $

See Also