Perl Diver 2.33
Main Environment Variables Perl Default Values Perl Config - Summary Perl Config - Full Installed Modules List Directory uptime Docs

Module Documentation
Details and documentation about a specific module, including version and documentation (if available). Note that while links to perldoc.com and search.cpan.org are provided, the module may be part of a larger distribution. If you reach a File Not Found page on either site, please try the parent module.

re::engine::RE2

Name re::engine::RE2
Version 0.14
Located at /usr/lib/x86_64-linux-gnu/perl5/5.34
File /usr/lib/x86_64-linux-gnu/perl5/5.34/re/engine/RE2.pm
Is Core No
Search CPAN for this module re::engine::RE2
Documentation re::engine::RE2
Module Details re::engine::RE2


NAME

re::engine::RE2 - RE2 regex engine


SYNOPSIS

    use re::engine::RE2;
    if ("Hello, world" =~ /Hello, (world)/) {
        print "Greetings, $1!";
    }


DESCRIPTION

This module replaces perl's regex engine in a given lexical scope with RE2.

RE2 is a primarily DFA based regexp engine from Google that is very fast at matching large amounts of text. However it does not support look behind and some other Perl regular expression features. See RE2's website for more information.

Fallback to normal Perl regexp is implemented by this module. If RE2 is unable to compile a regexp it will use Perl instead, therefore features not implemented by RE2 don't suddenly stop working, they will just use Perl's regexp implementation.


METHODS

To access extra functionality of RE2 methods can be called on a compiled regular expression (i.e. a qr//).


PRAGMA OPTIONS

Various options can be set by providing options to the use line. These will be pragma scoped.


PERFORMANCE

Performance is really the primary reason for using RE2, so here's some benchmarks. Like any benchmark take them with a pinch of salt.

Simple matching

  my $foo = "foo bar baz";
  $foo =~ /foo/;
  $foo =~ /foox/;

On this very simple match RE2 is actually slower:

           Rate  re2   re
  re2  674634/s   -- -76%
  re  2765739/s 310%   --

URL matching

Matching m{([a-zA-Z][a-zA-Z0-9]*)://([^ /]+)(/[^ ]*)?|([^ @]+)@([^ @]+)} against a several KB file:

        Rate    re   re2
  re  35.2/s    --  -99%
  re2 2511/s 7037%    --

Many alternatives

Matching a string against a regexp with 17,576 alternatives (aaa .. zzz).

This uses trie matching on Perl (obviously RE2 does similar by default).

  $ perl misc/altern.pl
          Rate   re  re2
  re   52631/s   -- -91%
  re2 554938/s 954%   --


NOTES


BUGS

Known issues:

Please report bugs or provide patches at <https://github.com/dgl/re-engine-RE2>.


AUTHORS

David Leadbeater <dgl[at]dgl[dot]cx>


COPYRIGHT

Copyright 2010 David Leadbeater.

Based on the re::engine::PCRE manpage:

Copyright 2007 Ævar Arnfjörð Bjarmason.

The original version was copyright 2006 Audrey Tang <cpan@audreyt.org> and Yves Orton.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

(However the bundled copy of RE2 has a different copyright owner and is under a BSD-like license, see re2/LICENSE.)

Perl Diver brought to you by ScriptSolutions.com © 1997- 2026