Getting the start / end of string in regex through match objects

Fredrik Lundh fredrik at pythonware.com
Mon Jan 9 10:02:08 EST 2006


"ankit" wrote:

>I want to get the start and end of all the patterns mattched in regex.
> I know I can get it with start() and end() fn of matched objects. But
> re.search() return the match object of first matching regex in the
> string. I want all match objects in that string

    for m in re.finditer(pattern, string):
        print m.start(), m.end()

(or use the start offset to re.search)

</F> 






More information about the Python-list mailing list