Regexp::Optimizer(3pm)

Regexp::Optimizer3pm

Optimizes regular expressions

Usage

  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 $

Export

none.

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.

Caveat

??{CODE} used

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

not idempotent

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))/

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/>

Acknowledgements

Releases

8 releases since Debian 6.0 (Squeeze); the text changed 4 times.

  1. 6.0
  2. 7
  3. 8–10
  4. 11
  5. 12–13

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.

From libregexp-optimizer-perl 0.23-3 in Debian 13 (Trixie). Parsed by carta from the page's man source.