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


Groups > comp.lang.python > #18437

Re: Repeating assertions in regular expression

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <jeanpierreda@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.011
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'mrab': 0.04; 'python': 0.08; 'failing': 0.09; '"should': 0.16; 'abort': 0.16; 'assertion': 0.16; 'benefit.': 0.16; 'optimised': 0.16; 'repetition': 0.16; 'skip:\xc2 30': 0.16; 'subject:expression': 0.16; 'subject:regular': 0.16; 'wording': 0.16; 'meant': 0.17; 'wrote:': 0.18; '>>>': 0.18; 'instance': 0.18; 'repeated': 0.18; 'jan': 0.19; "aren't": 0.21; "doesn't": 0.22; 'header:In-Reply- To:1': 0.22; 'etc,': 0.23; 'url:mailman': 0.28; 'message- id:@mail.gmail.com': 0.28; 'pm,': 0.29; 'equivalent': 0.31; 'error.': 0.32; 'tue,': 0.32; 'url:listinfo': 0.32; 'instead': 0.33; 'received:209.85.160': 0.33; 'match': 0.34; 'to:addr:python- list': 0.34; 'it.': 0.34; 'received:209.85.160.46': 0.35; 'received:mail-pw0-f46.google.com': 0.35; 'url:python': 0.36; 'but': 0.37; 'run': 0.37; 'received:google.com': 0.37; 'could': 0.37; 'enough': 0.38; 'received:209.85': 0.38; 'put': 0.38; 'url:org': 0.39; 'why': 0.39; 'received:209': 0.40; 'to:addr:python.org': 0.40; 'worth': 0.61; 'cost': 0.63; 'believe': 0.65; '2012': 0.67; 'buy': 0.68; 'balanced': 0.84; 'optimisation': 0.84; 'cost,': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=6IRbnniILkKzhrdDdN0NK27891YP+LbU5BoTJk4o1I4=; b=MpXmn/OZLDUsRimgBAFwKe2MV5iBQoFPleCF61dKrmJfUYLEJm9IerJvbfmch3Igrl LEtrD1ICBdy4YZNSVxXi/VV19kulFk/SXgjs/BLrth5RtgpgsfQw8GibyQxkdY9Ksf2p DVEi2ozAFf8gxbP7riJOomnTWS9SOvtQsZ79w=
MIME-Version 1.0
In-Reply-To <4F034FA3.6020902@mrabarnett.plus.com>
References <4f02c069$0$690$426a74cc@news.free.fr> <CABicbJKshBFOBgVNAmmGL6q7=3tz_QG2OYbGiS62HcaW2W=JmQ@mail.gmail.com> <4F034FA3.6020902@mrabarnett.plus.com>
From Devin Jeanpierre <jeanpierreda@gmail.com>
Date Tue, 3 Jan 2012 14:36:00 -0500
Subject Re: Repeating assertions in regular expression
To python-list@python.org
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4373.1325619405.27778.python-list@python.org> (permalink)
Lines 49
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1325619405 news.xs4all.nl 6946 [2001:888:2000:d::a6]:50797
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:18437

Show key headers only | View raw


> Put simply, it doesn't occur often enough to be worth it. The cost
> outweighs the potential benefit.

I don't buy it. You could backtrack instead of failing for \b+ and
\b*, and it would be almost as fast as this optimization.

-- Devin

On Tue, Jan 3, 2012 at 1:57 PM, MRAB <python@mrabarnett.plus.com> wrote:
> On 03/01/2012 09:45, Devin Jeanpierre wrote:
>>>
>>>  \\b\\b and \\b{2} aren't equivalent ?
>>
>>
>> This sounds suspiciously like a bug!
>>
>>>  Why the wording is "should never" ? Repeating a zero-width assertion is
>>> not
>>>  forbidden, for instance :
>>>
>>>>>>  import re
>>>>>>  re.compile("\\b\\b\w+\\b\\b")
>>>
>>>  <_sre.SRE_Pattern object at 0xb7831140>
>>>>>>
>>>>>>
>>
>> I believe this is meant to refer to arbitrary-length repetitions, such
>> as r'\b*', not simple concatenations like that. r'\b*' will abort the
>> whole match if is run on a boundary, because Python detects a
>> repetition of a zero-width match and decides this is an error.
>>
> r"\b+" can be optimised to r"\b", but r"\b*" can be optimised to r"".
> r"\b\b", r"\b\b\b", etc, can be optimised to r"\b".
>
> So why doesn't it optimised?
>
> Because every potential optimisation has a cost, which is the time it
> would take to look for it.
>
> That cost needs to be balanced against the potential benefit.
>
> How often do you see repeated r"\b"?
>
> Put simply, it doesn't occur often enough to be worth it. The cost
> outweighs the potential benefit.
> --
> http://mail.python.org/mailman/listinfo/python-list

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


Thread

Repeating assertions in regular expression candide <candide@free.invalid> - 2012-01-03 09:46 +0100
  Re: Repeating assertions in regular expression Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-01-03 04:45 -0500
  Re: Repeating assertions in regular expression MRAB <python@mrabarnett.plus.com> - 2012-01-03 18:57 +0000
  Re: Repeating assertions in regular expression Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-01-03 14:36 -0500

csiph-web