Positions of regexp groups

Magnus Lie Hetland mlh at selje.idi.ntnu.no
Sun Apr 10 08:44:45 EDT 2005


In article <mailman.1535.1112968172.1799.python-list at python.org>, Tim
Peters wrote:
>[Magnus Lie Hetland]
>> Just a quick question: Does anyone have a simple way of finding the
>> positions (start, end) of the groups in a regexp match? AFAICS, the re
>> API can only return the contents...?
>
>Read the docs for match objects, esp. the start(), end(), and span()
>methods.

Right. I was just now editing the regex-stuff in my book for the
second edition, and found that I had, in fact, written about just this
behaviour. <blush/>

Oh, well. I guess it's a feature I don't use much :}

Thanks, anyway.

-- 
Magnus Lie Hetland                    Fall seven times, stand up eight
http://hetland.org                                  [Japanese proverb]



More information about the Python-list mailing list