Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'received:localnet': 0.07; 'python': 0.08; 'append': 0.09; 'either.': 0.09; 'matt': 0.09; 'suggestion.': 0.09; 'subject:python': 0.11; '"copyright",': 0.16; '"credits"': 0.16; '"license"': 0.16; '[gcc': 0.16; 'alain': 0.16; 'linux2': 0.16; 'route.': 0.16; 'subject:expression': 0.16; 'subject:regular': 0.16; 'top-post': 0.16; 'question.': 0.16; 'wrote:': 0.16; 'subject:Help': 0.17; 'figure': 0.21; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; '(where': 0.23; 'retaining': 0.23; 'writes:': 0.25; 'guess': 0.26; 'string': 0.26; 'skip:[ 10': 0.27; 'work.': 0.27; 'problem': 0.28; 'import': 0.28; 'matches': 0.29; 'match': 0.30; 'times.': 0.30; 'thanks': 0.30; "skip:' 10": 0.30; "didn't": 0.31; 'apr': 0.32; 'expression': 0.32; 'it.': 0.33; "can't": 0.33; 'there': 0.33; 'to:addr:python-list': 0.33; 'header:User-Agent:1': 0.34; 'message-id:@gmail.com': 0.34; 'numbers.': 0.34; 'another': 0.37; 'convenient': 0.37; 'friday,': 0.37; 'using': 0.37; 'but': 0.37; 'received:128': 0.38; 'think': 0.38; 'some': 0.38; 'received:google.com': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.39; 'i.e.': 0.39; 'getting': 0.39; 'ways': 0.39; 'help': 0.39; 'subject:with': 0.39; 'are:': 0.39; 'data': 0.39; 'why': 0.39; 'to:addr:python.org': 0.39; 'greatly': 0.40; 'where': 0.40; 'more': 0.60; 'your': 0.61; 'results': 0.61; 'header:Message-Id:1': 0.61; 'plus': 0.65; 'as:': 0.70; 'august': 0.70; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.71; 'reply-to:addr:gmail.com': 0.78; 'obtained': 0.80; 'funk': 0.84; 'data)': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:reply-to:to:subject:date:user-agent:references:in-reply-to :mime-version:content-type:content-transfer-encoding:message-id; bh=VoUb+QpizLoQqmUt8T0TMmmintwc6Qqbvo6fwPXEd8c=; b=NLlSzw6DFBL63oj2fxpaXKk/5u0WQHhMrPyliuH/6Cx/cPRFtjNAQDqJ3/AkF5TFqF 9zzfZY+d64iQ2K4pfVjFa9euW2gdZzv2yVog5bbkvwv0BIOzgmI/BcMHtmJTNNEOlJO4 rEX0LnVtiMxqpnYTPThFrAy7fJFz4M/0wT5Ug= From: Matt Funk To: python-list@python.org Subject: Re: Help with regular expression in python Date: Fri, 19 Aug 2011 11:33:49 -0600 User-Agent: KMail/1.13.6 (Linux/2.6.38-10-server; KDE/4.6.2; x86_64; ; ) References: <201108181349.54727.matze999@gmail.com> <87hb5d4cik.fsf@dpt-info.u-strasbg.fr> In-Reply-To: <87hb5d4cik.fsf@dpt-info.u-strasbg.fr> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: matze999@gmail.com List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 72 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1313775252 news.xs4all.nl 23903 [2001:888:2000:d::a6]:35022 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:11860 On Friday, August 19, 2011, Alain Ketterlin wrote: > Matt Funk 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. Anyway, i think at this point i will go another route. Not sure where the issues lies at this point. thanks for all the help matt > > There are better ways to build your regexp, but I think this one is > convenient to answer your question. You still have to append what will > match the end of the line. > > -- Alain. > > P/S: please do not top-post > > >> $ python > >> Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) > >> [GCC 4.4.3] on linux2 > >> Type "help", "copyright", "credits" or "license" for more information. > >> > >>>>> data > >> > >> '1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01 > >> 1.914000e+01 2.007000e+01 1.664000e+01 2.204000e+01 2.109000e+01 > >> 2.209000e+01 2.376000e+01 2.158000e+01 2.177000e+01 2.152000e+01 > >> 2.267000e+01 1.084000e+01 1.671000e+01 1.888000e+01 1.854000e+01 > >> 2.064000e+01 2.000000e+01 2.200000e+01 2.139000e+01 2.137000e+01 > >> 2.178000e+01 2.179000e+01 2.123000e+01 2.201000e+01 2.150000e+01 > >> 2.150000e+01 2.199000e+01 : (instance: 0) : some > >> description' > >> > >>>>> import re > >>>>> re.findall(r"\d\.\d+e\+\d+", data) > >> > >> ['1.002000e+01', '2.037000e+01', '2.128000e+01', '1.908000e+01', > >> '1.871000e+01', '1.914000e+01', '2.007000e+01', '1.664000e+01', > >> '2.204000e+01', '2.109000e+01', '2.209000e+01', '2.376000e+01', > >> '2.158000e+01', '2.177000e+01', '2.152000e+01', '2.267000e+01', > >> '1.084000e+01', '1.671000e+01', '1.888000e+01', '1.854000e+01', > >> '2.064000e+01', '2.000000e+01', '2.200000e+01', '2.139000e+01', > >> '2.137000e+01', '2.178000e+01', '2.179000e+01', '2.123000e+01', > >> '2.201000e+01', '2.150000e+01', '2.150000e+01', '2.199000e+01']