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


Groups > comp.lang.python > #11880

Re: Help with regular expression in python

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '"if': 0.04; 'url:pypi': 0.08; '>>>>': 0.09; 'either.': 0.09; 'from:addr:python': 0.09; 'matt': 0.09; 'suggestion.': 0.09; 'subject:python': 0.11; 'am,': 0.12; 'alain': 0.16; 'capturing': 0.16; 'docs,': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'matched': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:84.92': 0.16; 'received:84.92.122': 0.16; 'received:84.92.122.60': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'reply-to:addr:python-list': 0.16; 'subject:expression': 0.16; 'subject:regular': 0.16; 'wrote:': 0.16; 'subject:Help': 0.17; '>>>': 0.18; 'figure': 0.21; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; '(where': 0.23; 'retaining': 0.23; 'times,': 0.24; 'writes:': 0.25; 'guess': 0.26; 'string': 0.26; 'work.': 0.27; 'received:84': 0.28; 'problem': 0.28; 'matches': 0.29; 'specifically': 0.29; 'match': 0.30; 'times.': 0.30; 'pattern': 0.30; 'thanks': 0.30; "didn't": 0.31; 'expression': 0.32; 'does': 0.32; 'it.': 0.33; "can't": 0.33; 'to:addr:python-list': 0.33; 'header:User-Agent:1': 0.34; 'numbers.': 0.34; 'reply-to:addr:python.org': 0.34; 'url:python': 0.36; 'another': 0.37; 'friday,': 0.37; 'using': 0.37; 'but': 0.37; 'url:org': 0.38; 'subject:: ': 0.39; 'i.e.': 0.39; 'getting': 0.39; 'subject:with': 0.39; "there's": 0.39; 'are:': 0.39; 'why': 0.39; 'to:addr:python.org': 0.39; 'greatly': 0.40; 'where': 0.40; 'more': 0.60; 'results': 0.61; 'plus': 0.65; 'email addr:yahoo.com': 0.66; 'past.': 0.67; 'as:': 0.70; 'august': 0.70; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.71; 'obtained': 0.80; 'secret': 0.82; '11:33': 0.84; 'funk': 0.84
X-IronPort-Anti-Spam-Filtered true
X-IronPort-Anti-Spam-Result AuoBAPjJTk5UXebj/2dsb2JhbABCmCwPNY8dd4FAAQEFOEARCwgQCRYPCQMCAQIBDQIkEhMGAgEBh28CuGaGSASLX0mLd4RqhwA
Date Fri, 19 Aug 2011 21:43:55 +0100
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:6.0) Gecko/20110812 Thunderbird/6.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Help with regular expression in python
References <201108181349.54727.matze999@gmail.com> <mailman.222.1313767221.27778.python-list@python.org> <87hb5d4cik.fsf@dpt-info.u-strasbg.fr> <mailman.227.1313775252.27778.python-list@python.org> <58c66ba7-daf6-4e98-ba26-e054d9fde5f0@z17g2000vbp.googlegroups.com>
In-Reply-To <58c66ba7-daf6-4e98-ba26-e054d9fde5f0@z17g2000vbp.googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To python-list@python.org
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.238.1313786638.27778.python-list@python.org> (permalink)
Lines 43
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1313786638 news.xs4all.nl 23890 [2001:888:2000:d::a6]:38264
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:11880

Show key headers only | View raw


On 19/08/2011 20:55, rurpy@yahoo.com wrote:
> On 08/19/2011 11:33 AM, Matt Funk wrote:
>> On Friday, August 19, 2011, Alain Ketterlin wrote:
>>> Matt Funk<matze999@gmail.com>  writes:
>>>> thanks for the suggestion. I guess i had found another way around the
>>>> problem as well. But i really wanted to match the line exactly and i
>>>> wanted to know why it doesn't work. That is less for the purpose of
>>>> getting the thing to work but more because it greatly annoys me off that
>>>> i can't figure out why it doesn't work. I.e. why the expression is not
>>>> matches {32} times. I just don't get it.
>>>
>>> Because a line is not 32 times a number, it is a number followed by 31
>>> times "a space followed by a number". Using Jason's regexp, you can
>>> build the regexp step by step:
>>>
>>> number = r"\d\.\d+e\+\d+"
>>> numbersequence = r"%s( %s){31}" % (number,number)
>> That didn't work either. Using the (modified (where the (.+) matches the end of
>> the line)) expression as:
>>
>> number = r"\d\.\d+e\+\d+"
>> numbersequence = r"%s( %s){31}(.+)" % (number,number)
>> instance_linetype_pattern = re.compile(numbersequence)
>>
>> The results obtained are:
>> results:
>> [(' 2.199000e+01', ' : (instance: 0)\t:\tsome description')]
>> so this matches the last number plus the string at the end of the line, but no
>> retaining the previous numbers.
>
> The secret is buried very unobtrusively in the re docs,
> where it has caught me out in the past.  Specifically
> in the docs for re.group():
>
>    "If a group is contained in a part of the pattern that
>    matched multiple times, the last match is returned."
>
[snip]
There's a regex implementation on PyPI:

     http://pypi.python.org/pypi/regex

which does support capturing all of the matches of a group.

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


Thread

Re: Help with regular expression in python Matt Funk <matze999@gmail.com> - 2011-08-19 09:20 -0600
  Re: Help with regular expression in python jmfauth <wxjmfauth@gmail.com> - 2011-08-19 08:50 -0700
  Re: Help with regular expression in python Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2011-08-19 18:00 +0200
    Re: Help with regular expression in python Matt Funk <matze999@gmail.com> - 2011-08-19 11:33 -0600
      Re: Help with regular expression in python jmfauth <wxjmfauth@gmail.com> - 2011-08-19 11:40 -0700
        Re: Help with regular expression in python Matt Funk <matze999@gmail.com> - 2011-08-19 15:21 -0600
      Re: Help with regular expression in python "rurpy@yahoo.com" <rurpy@yahoo.com> - 2011-08-19 12:55 -0700
        Re: Help with regular expression in python MRAB <python@mrabarnett.plus.com> - 2011-08-19 21:43 +0100
      Re: Help with regular expression in python Carl Banks <pavlovevidence@gmail.com> - 2011-08-19 13:11 -0700
        Re: Help with regular expression in python Matt Funk <matze999@gmail.com> - 2011-08-19 15:55 -0600
        Re: Help with regular expression in python Vlastimil Brom <vlastimil.brom@gmail.com> - 2011-08-22 15:59 +0200

csiph-web