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


Groups > comp.lang.python > #5527

Re: regular expression i'm going crazy

Date 2011-05-16 19:01 +0200
From Alexander Kapps <alex.kapps@web.de>
Subject Re: regular expression i'm going crazy
References <4dd14fdb$0$18238$4fafbaef@reader2.news.tin.it>
Newsgroups comp.lang.python
Message-ID <mailman.1648.1305565658.9059.python-list@python.org> (permalink)

Show all headers | 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