Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #18396

Re: Regular expression : non capturing groups are faster ?

References <4f02e31c$0$15724$426a74cc@news.free.fr>
From Devin Jeanpierre <jeanpierreda@gmail.com>
Date 2012-01-03 06:56 -0500
Subject Re: Regular expression : non capturing groups are faster ?
Newsgroups comp.lang.python
Message-ID <mailman.4346.1325591848.27778.python-list@python.org> (permalink)

Show all headers | View raw


> The second assertion sounds more likely. It seems very odd that Python and
> Perl implementations are divergent on this point. Any opinion ?

The Python documentation oversimplifies. What it means to say is that
while one might expect capturing matches to do extra work proportional
to the capture, they do not. They don't do anything other than mark
down where to extract submatches, and the extra work done is pretty
much negligible. (That is, the work done for submatch extraction is a
polynomial (looks like quadratic) in the number of capturing groups
(which is very small almost always), with a small coefficient).

The Perl documentation is technically correct, but if the HOWTO said
it, it would give the wrong impression. You shouldn't care about
capturing vs noncapturing except with regards to how it interferes
with your group numbering scheme.

-- Devin

On Tue, Jan 3, 2012 at 6:14 AM, candide <candide@free.invalid> wrote:
> Excerpt from the Regular Expression HOWTO
> (http://docs.python.org/howto/regex.html#non-capturing-and-named-groups) :
>
>
> -----------------------------------------------
> It should be mentioned that there’s no performance difference in searching
> between capturing and non-capturing groups; neither form is any faster than
> the other.
> -----------------------------------------------
>
>
> Now from the Perl Regular Expression tutorial
> (http://perldoc.perl.org/perlretut.html#Non-capturing-groupings) :
>
>
> -----------------------------------------------
> Because there is no extraction, non-capturing groupings are faster than
> capturing groupings.
> -----------------------------------------------
>
>
> The second assertion sounds more likely. It seems very odd that Python and
> Perl implementations are divergent on this point. Any opinion ?
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Regular expression : non capturing groups are faster ? candide <candide@free.invalid> - 2012-01-03 12:14 +0100
  Re: Regular expression : non capturing groups are faster ? Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-01-03 06:56 -0500
    Re: Regular expression : non capturing groups are faster ? candide <candide@free.invalid> - 2012-01-03 15:50 +0100
      Re: Regular expression : non capturing groups are faster ? Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-01-03 14:31 -0500
      Re: Regular expression : non capturing groups are faster ? "Octavian Rasnita" <orasnita@gmail.com> - 2012-01-03 22:07 +0200
      Re: Regular expression : non capturing groups are faster ? Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-01-03 15:38 -0500
  Re: Regular expression : non capturing groups are faster ? "Octavian Rasnita" <orasnita@gmail.com> - 2012-01-03 13:59 +0200

csiph-web