Re: Odd behaviour of regexp module
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: Odd behaviour of regexp module

From: Martin <clamhan@hotmail.com>
Date: Wed Jul 13 2005 - 23:39:32 CEST

Hi David,
              b.group() is equivalent to b.group(0), the entire RE
match. (^(.*?)\.) will give you 'dfsf.' for that input string.

What you want is b.group(1), the subgroup you're looking for inside
the main RE. (.*?) which gives you 'dfsf', which is what you're
looking for.

Cheers,
            Martin

On 13 Jul 2005 14:05:37 -0700, "David Veerasingam"
<vdavidster@gmail.com> wrote:

>Hello
>
>It seems the grouping feature isn't behaving correctly.
>
>In [1]: a = 'dfsf.oct.ocfe'
>
>In [2]: b = re.match(r'^(.*?)\.', a); b.group()
>'dfsf.'
>
>The expected result is 'dfsf'. Why did the regexp grab that period at
>the end?
>
>David
Received on Thu Sep 29 16:56:28 2005