regular expression question

Steve Lamb grey at despair.dmiyu.org
Wed Jan 21 03:02:01 CET 2004


On 2004-01-21, Ben Finney <bignose-hates-spam at and-benfinney-does-too.id.au>
wrote:
> On Wed, 21 Jan 2004 00:38:12 -0000, Steve Lamb wrote:
>> import re line = 'match this' foo = re.search(r'.*(this)', line)
>> foo.groups()[0]

>     >>> import re line = 'match this' foo = re.search( r'.*(this)', line )
>     >>> foo.groups()
>     ('this',)
>     >>> foo.group(0)
>     'match this'
>     >>> foo.group(1)
>     'this'

> Read more on the methods available from a MatchObject:

    Fsck.  Of course the groups are numbered from 1 but if one goes by the
tuple returned they are numbered from 0.  That was my mistake.  Thanks for
pointing it out to me.  :P

-- 
         Steve C. Lamb         | I'm your priest, I'm your shrink, I'm your
       PGP Key: 8B6E99C5       | main connection to the switchboard of souls.
-------------------------------+---------------------------------------------



More information about the Python-list mailing list