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


Groups > comp.lang.python > #5527

Re: regular expression i'm going crazy

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <alex.kapps@web.de>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.045
X-Spam-Evidence '*H*': 0.91; '*S*': 0.00; '"if': 0.04; 'this:': 0.11; 'wrote:': 0.14; 'message-id:@web.de': 0.16; 'parentheses:': 0.16; 'subject:expression': 0.16; 'subject:regular': 0.16; 'header:In- Reply-To:1': 0.22; 'list': 0.30; 'from:addr:web.de': 0.31; 'url:library': 0.31; 'import': 0.32; 'to:addr:python-list': 0.32; 'url:docs': 0.33; 'print': 0.35; 'header:User-Agent:1': 0.35; 'fixing': 0.35; 'url:python': 0.37; 'url:org': 0.38; 'help': 0.39; 'docs': 0.39; 'to:addr:python.org': 0.39; 'received:de': 0.39; 'link': 0.62; 'received:172.20': 0.73; 'sender:addr:web.de': 0.84
Date Mon, 16 May 2011 19:01:35 +0200
From Alexander Kapps <alex.kapps@web.de>
User-Agent Mozilla/5.0 (X11; U; Linux i686; de-DE; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8
MIME-Version 1.0
To python-list@python.org
Subject Re: regular expression i'm going crazy
References <4dd14fdb$0$18238$4fafbaef@reader2.news.tin.it>
In-Reply-To <4dd14fdb$0$18238$4fafbaef@reader2.news.tin.it>
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
Sender alex.kapps@web.de
X-Sender Alex.Kapps@web.de
X-Provags-ID V01U2FsdGVkX18y/okh8hpv6FBmyZ2hAZ+w+XOIw5yOyf3fsNsb yk9dQ6+yp7nOeaG0s9iFYkolW7dUVASsPn8iTyqzYqgFIHVxhm AFFT4Bpi4=
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.1648.1305565658.9059.python-list@python.org> (permalink)
Lines 27
NNTP-Posting-Host 82.94.164.166
X-Trace 1305565658 news.xs4all.nl 49031 [::ffff:82.94.164.166]:42147
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:5527

Show key headers only | View raw


On 16.05.2011 18:25, Tracubik wrote:
> pls help me fixing this:
>
> import re
> s = "linka la baba"
> re_s = re.compile(r'(link|l)a' , re.IGNORECASE)
>
> print re_s.findall(s)
>
> output:
> ['link', 'l']
>
> why?

As the docs say:

"If one or more groups are present in the pattern, return a list of 
groups;"

http://docs.python.org/library/re.html?highlight=findall#re.findall

> i want my re_s to find linka and la, he just find link and l and forget
> about the ending a.

Try with non-grouping parentheses:

re_s = re.compile(r'(?:link|l)a' , re.IGNORECASE)

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


Thread

regular expression i'm going crazy Tracubik <affdfsdfdsfsd@b.com> - 2011-05-16 16:25 +0000
  Re: regular expression i'm going crazy Robert Kern <robert.kern@gmail.com> - 2011-05-16 11:51 -0500
  Re: regular expression i'm going crazy Alexander Kapps <alex.kapps@web.de> - 2011-05-16 19:01 +0200
  Re: regular expression i'm going crazy andy baxter <andy@earthsong.free-online.co.uk> - 2011-05-16 18:11 +0100

csiph-web