June 2002
Beginner to intermediate
640 pages
14h 24m
English
The following sections describe the methods and properties of the match object.
<match object>.group([name|num][,name|num]...)
The group() method gets matches of each group of the expression, or all matches if no group is specified. If a single argument is passed, the return value is a string containing the group specified. If no arguments are passed, the return value is a string containing the entire match. If a group is in part of a pattern that doesn't match, the return value is None. If it's in part of the pattern that matches multiple times, the last match is returned.
>>> mo = search(r'(?P<first>t)(?P<last>est)',"test") >>> mo.group() 'test' >>> mo.group("first") 't' >>> mo.group("last") 'est' ...Read now
Unlock full access