MatchObject instances support the following methods and attributes:
If the regular expression uses the (?P<name>...) syntax, the groupN arguments may also be strings identifying groups by their group name.
A moderately complicated example:
m = re.match(r"(?P<int>\d+)\.(\d*)", '3.14')
After performing this match, m.group(1) is '3', as is m.group('int'), and m.group(2) is '14'.
m.string[m.start(g):m.end(g)]
Note that m.start(group) will equal m.end(group) if group matched a null string. For example, after m = re.search('b(c?)', 'cba'), m.start(0) is 1, m.end(0) is 2, m.start(1) and m.end(1) are both 2, and m.start(2) raises an IndexError exception.
See Also:
Jeffrey Friedl, Mastering Regular Expressions, O'Reilly. The Python material in this book dates from before the re module, but it covers writing good regular expression patterns in great detail.
guido@python.org