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


Groups > comp.lang.python > #11809

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 <vlastimil.brom@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; 'escape': 0.04; 'python': 0.08; 'expressions.': 0.09; 'matt': 0.09; 'subject:python': 0.11; 'backslashes': 0.16; "doesn't.": 0.16; 'offense': 0.16; 'prepended': 0.16; 'shed': 0.16; 'subject:expression': 0.16; 'subject:regular': 0.16; 'subject:Help': 0.17; 'figure': 0.21; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'received:209.85.212.46': 0.23; 'received:mail- vw0-f46.google.com': 0.23; "skip:' 40": 0.23; 'string': 0.26; '(in': 0.26; 'work.': 0.27; 'scientific': 0.28; 'problem': 0.28; 'url:mailman': 0.28; 'matches': 0.29; 'source,': 0.29; 'message- id:@mail.gmail.com': 0.29; 'example': 0.30; 'match': 0.30; 'times.': 0.30; 'character.': 0.30; 'line:': 0.30; 'pattern': 0.30; 'whitespace': 0.30; 'thanks': 0.30; 'expression': 0.32; 'go.': 0.32; 'hi,': 0.32; 'handling': 0.32; 'does': 0.32; 'it.': 0.33; 'there': 0.33; 'to:addr:python-list': 0.33; 'url:listinfo': 0.33; 'light': 0.34; 'however,': 0.34; 'someone': 0.34; 'quite': 0.34; 'received:209.85.212': 0.34; 'list.': 0.35; 'supposed': 0.35; 'regular': 0.35; 'url:python': 0.36; 'question': 0.36; 'using': 0.37; 'some': 0.38; 'received:google.com': 0.38; 'url:org': 0.38; 'received:209.85': 0.38; 'should': 0.38; 'subject:: ': 0.39; 'either': 0.39; 'subject:with': 0.39; 'format.': 0.39; 'why': 0.39; 'to:addr:python.org': 0.39; 'description': 0.39; "i'd": 0.40; 'raw': 0.40; 'where': 0.40; 'double': 0.61; 'subject': 0.61; 'order': 0.62; 'vary': 0.64; 'funk': 0.84; 'quotation': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=RQhlTa57WVgHATvp7y94Pqdm2sziNebS5GQcNuUkj90=; b=CKLRIHzuqHI3As2bgAbH2ExihjFDFWSzbwA576yClynjXZe0zpRFfVO1snMa6WgVuH zbwVRgVYRh489QDE1EmHaFMmXjG4K5zuqXV4fLCZ084WyNAWxYot1jufyPjdzM2fgn4W 1G+rRyeBwXoLpDhw9+roFLvNmUSL8qbwNzQfI=
MIME-Version 1.0
In-Reply-To <201108181349.54727.matze999@gmail.com>
References <201108181349.54727.matze999@gmail.com>
Date Thu, 18 Aug 2011 23:27:42 +0200
Subject Re: Help with regular expression in python
From Vlastimil Brom <vlastimil.brom@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
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.198.1313702865.27778.python-list@python.org> (permalink)
Lines 49
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1313702865 news.xs4all.nl 23917 [2001:888:2000:d::a6]:57801
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:11809

Show key headers only | View raw


2011/8/18 Matt Funk <matze999@gmail.com>:
> Hi,
> i am sorry if this doesn't quite match the subject of the list. If someone
> takes offense please point me to where this question should go. Anyway, i have
> a problem using regular expressions. I would like to match the line:
>
> 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
>
> The number of floats can vary (in this example there are 32). So what i thought
> i'd do is the following:
> instance_linetype_pattern_str = '([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)
> {32}'
> instance_linetype_pattern = re.compile(instance_linetype_pattern_str)
> Basically the expression in the first major set of paranthesis matches a
> scientific number format. The '{32}' is supposed to match the previous 32
> times. However, it doesn't. I  can't figure out why this does not work. I'd
> really like to understand it if someone can shed light on it.
>
> thanks
> matt
> --
> http://mail.python.org/mailman/listinfo/python-list
>
Hi,
the already suggested handling of whitespace with \s+ etc. at the end
of the parenthesised patern should help;
furhtermore, if you are using this pattern in the python source, you
should either double all backslashes or use a raw string for the
pattern - with r prepended before the opening quotation mark:
pattern_str = r"..."
in order to handle backslashes literally and not as escape character.
hth,
vbr

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


Thread

Re: Help with regular expression in python Vlastimil Brom <vlastimil.brom@gmail.com> - 2011-08-18 23:27 +0200

csiph-web