Giter Site home page Giter Site logo

renowncoder / re-engine-re2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dgl/re-engine-re2

0.0 1.0 0.0 448 KB

re::engine::RE2 - RE2 regexp engine interface for Perl

Home Page: http://search.cpan.org/dist/re-engine-RE2

C 20.77% Perl 1.40% Makefile 0.61% C++ 75.06% Python 1.63% Shell 0.02% XS 0.11% Objective-C 0.03% Raku 0.35%

re-engine-re2's Introduction

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
    http://code.google.com/p/re2 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//").

    *   "possible_match_range([length = 10])"

        Returns an array of two strings: where the expression will start
        matching and just after where it will finish matching. See RE2's
        documentation on PossibleMatchRange for further details.

        Example:

            my($min, $max) = qr/^(a|b)/->possible_match_range;
            is $min, 'a';
            is $max, 'c';'

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
    *   No support for "m//x"

        The "/x" modifier is not supported. (There's no particular reason
        for this, just RE2 itself doesn't support it). Fallback to Perl
        regexp will happen automatically if "//x" is used.

    *   "re2/dfa.cc:447: DFA out of memory: prog size xxx mem yyy"

        If you attempt to compile a really large regular expression you may
        get this error. RE2 has an internal limit on memory consumption for
        the DFA state tables. By default this is 8 MiB.

        If you need to increase this size then use the max_mem parameter:

          use re::engine::RE2 -max_mem => 8<<23; # 64MiB

    *   How do I tell if RE2 will be used?

        See if your regexp is matching quickly or slowly ;).

        Alternatively normal OO concepts apply and you may examine the
        object returned by "qr//":

          use re::engine::RE2;

          ok qr/foo/->isa("re::engine::RE2");

          # Perl Regexp used instead
          ok not qr/(?<=foo)bar/->isa("re::engine::RE2");

BUGS
    Known issues:

    *   Unicode handling

        Currently the Unicode handling of re::engine::RE2 does not fully
        match Perl's behaviour.

        The UTF-8 flag of the regexp currently determines how the string is
        matched. This is obviously broken, so will be fixed at some point.

    *   Final newline matching differs to Perl

          "\n" =~ /$/

        The above is true in Perl, false in RE2. To work around the issue
        you can write "\n?\z" when you mean Perl's "$".

    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 re::engine::PCRE:

    Copyright 2007 Ævar Arnfjörð Bjarmason.

    The original version was copyright 2006 Audrey Tang <[email protected]>
    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.)

re-engine-re2's People

Contributors

dgl avatar oylenshpeegul avatar rouzier avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.