Regular expression returning an index where match was found?
James Henderson
james at logicalprogression.net
Thu Jul 8 12:15:18 EDT 2004
On Thursday 08 July 2004 4:15 pm, Jon Nicoll wrote:
> Hi All
> I would like to be able to use regular expression searches to
> determine the index(es) within a string where a match was found. ie.,
> given
>
> import re
>
> def myFunc():
> # to be written ;-)
>
> the call
>
> myfunc("abc", "abcdefabcabc")
>
> would return (say) a list [0, 6, 9]
>
> I can't see a straightforward way of doing this from reading the
> Regular Expression HOWTO and the python docs; any
> pointers/suggestions?
>
> Thanks
> Jon N
I belive you want the start() and end() methods of a match object. They are
in the docs:
http://www.python.org/doc/current/lib/match-objects.html
James
--
James Henderson, Logical Progression Ltd
http://www.logicalprogression.net
http://mailmanager.sourceforge.net
More information about the Python-list
mailing list