Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #74048

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

Date 2014-07-06 20:13 +0100
From MRAB <python@mrabarnett.plus.com>
Subject Re: What is the difference between matchObj.group() and matchObj.group(0)
References <809dbbdf-b452-4f25-a1ff-f00a2202939d@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.11554.1404674030.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 2014-07-06 19:26, rxjwg98@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.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

What is the difference between matchObj.group() and matchObj.group(0) rxjwg98@gmail.com - 2014-07-06 11:26 -0700
  Re: What is the difference between matchObj.group() and matchObj.group(0) MRAB <python@mrabarnett.plus.com> - 2014-07-06 20:13 +0100

csiph-web