What is the difference between matchObj.group() and matchObj.group(0)

MRAB python at mrabarnett.plus.com
Sun Jul 6 15:13:46 EDT 2014


On 2014-07-06 19:26, rxjwg98 at gmail.com wrote:
> Hi,
>
> I cannot get the difference between matchObj.group() and matchObj.group(0),
> Although there definitions are obvious different. And group() mentions 'tuple'.
> tuple means all the elements in line object?
>
>
>
> Match Object Methods
>
> Description
>
> group(num=0) This method returns entire match (or specific subgroup num)
> groups()     This method returns all matching subgroups in a tuple
>               (empty if there weren't any)
>
>
>
> I run the following code. Even I add more words to line object, Both have the
> same output.
>
> Could you clarify this question?
>
matchObj.group(g) returns what was captured by group g.

If you don't specify the group, it'll assume that you want group 0,
which is the entire part of the string that matched.




More information about the Python-list mailing list