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: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.020 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'see:': 0.07; 'from:addr:andy': 0.09; 'this:': 0.11; '>>>': 0.12; 'wrote:': 0.14; 'brackets': 0.16; 'brackets.': 0.16; 'subject:expression': 0.16; 'subject:regular': 0.16; '(which': 0.21; 'header:In-Reply- To:1': 0.22; "what's": 0.24; 'define': 0.26; 'string': 0.29; 'elements': 0.29; 'matches': 0.29; 'tuples': 0.31; 'match': 0.31; 'import': 0.32; 'to:addr:python-list': 0.32; 'array': 0.33; 'print': 0.35; 'header:User-Agent:1': 0.35; 'fixing': 0.35; 'round': 0.35; 'url:python': 0.37; 'element': 0.38; 'help': 0.39; 'set': 0.39; 'to:addr:python.org': 0.39; 'i.e.': 0.40; 'link': 0.62; 'url:info': 0.76; 'received:2': 0.91 Date: Mon, 16 May 2011 18:11:01 +0100 From: andy baxter User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110424 Thunderbird/3.1.10 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=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam-SpamPro: 1.2 X-Spam-Score: -1.0 (-) X-Antivirus-Scanner: Clean mail though you should still use an Antivirus X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server28.dayanadns.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - earthsong.free-online.co.uk X-Source: X-Source-Args: X-Source-Dir: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list 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: 29 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1305565877 news.xs4all.nl 49040 [::ffff:82.94.164.166]:52841 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:5528 On 16/05/11 17: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? > i want my re_s to find linka and la, he just find link and l and forget > about the ending a. The round brackets define a 'capturing group'. I.e. when you do findall it returns those elements in the string that match what's inside the brackets. If you want to get linka and la, you need something like this: >>> re_s = re.compile(r'((link|l)a)' , re.IGNORECASE) >>> print re_s.findall(s) [('linka', 'link'), ('la', 'l')] Then just look at the first element in each of the tuples in the array (which matches the outside set of brackets). see: http://www.regular-expressions.info/python.html