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

ankit ankitrastogi82 at
Mon Jan 9 09:54:33 EST 2006

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 return the match object of first matching regex in the
string. I want all match objects in that string

Here is the string :

tmplstr = """

  an element     ${elem:parentlst}

  an element     ${elem:childlst}

Here is the regex script:

 # Compile List Patterns
        # Start of List
        lstpattern_st = r"(\$\{list:([a-z]*[0-9 ]*)\})"
        lstpat_st = re.compile(lstpattern_st)

        # End of List
        lstpattern_end = r"(\$\{/list:([a-z]*[0-9 ]*)\})"
        lstpat_e = re.compile(lstpattern_end, re.I)

        matchgrp_st =
        strt = matchgrp_st.start()
        print strt
        matchgrp_e =
        end = matchgrp_e.end()
        print end
        print self.tmplstr[strt:end]

I want all the start and end indices of the string but
returns the first regex met in the string. re.match() also wont work
because it search in the begining.

Can anyone help me in getting the start and end indices of all. OR can
provide any other solution instead of this

More information about the Python-list mailing list