MatchObject instances support the following methods andattributes:
None. If a group is contained in apart of the pattern that matched multiple times, the last match isreturned.If the regular expression uses the(?P<name>...) syntax,thegroupN arguments may also be strings identifying groups bytheir group name. If a string argument is not used as a group name inthe pattern, anIndexError exception is raised.
A moderately complicated example:
m = re.match(r"(?P<int>\d+)\.(\d*)", '3.14')
After performing this match,m.group(1) is'3', as ism.group('int'), andm.group(2) is'14'.
None. (Incompatibility note: in the original Python 1.5release, if the tuple was one element long, a string would be returnedinstead. In later versions (from 1.5.1 on), a singleton tuple isreturned in such cases.)None.-1 ifgroup exists butdid not contribute to the match. For a match objectm, and a groupg that did contribute to the match, thesubstring matched by groupg (equivalent tom.group(g)) ism.string[m.start(g):m.end(g)]
Note thatm.start(group) will equalm.end(group) ifgroup matched a null string. For example, afterm =re.search('b(c?)', 'cba'),m.start(0) is 1,m.end(0) is 2,m.start(1) andm.end(1) are both 2, andm.start(2) raisesanIndexError exception.
(m.start(group),m.end(group)).Note that ifgroup did not contribute to the match, this is(-1, -1). Again,group defaults to zero.None if thegroup didn't have a name, or if no group was matched at all.Noneif no group was matched at all.| Python Library Reference |