again problem with re.reserch

Alex Martelli aleaxit at yahoo.com
Tue Jul 31 06:03:34 EDT 2001


"sdf" <wqh-2 at 263.net> wrote in message
news:mailman.996548997.18654.python-list at python.org...
> >None
> >>>> c = a.search('foo abcd')
> >>>> print c
> ><SRE_Match object at 0x8114a28>
> >>>>
> >
> ****************
>
>        then how I can get the exact postion the string in 'foo abcd',
> for example ,I want it return a number denote the postion

The match-object c has the methods you need.  For example:

>>> import re
>>> a=re.compile('abc')
>>> c=a.search('foo abcd')
>>> c
<SRE_Match object at 00820010>
>>> dir(c)
['end', 'expand', 'group', 'groupdict', 'groups', 'span', 'start']
>>> c.start
<built-in method start of SRE_Match object at 00820010>
>>> c.start()
4
>>> c.end()
7
>>> c.span()
(4, 7)
>>>


Alex






More information about the Python-list mailing list