Narendra <cnrpr...@gmail.com> added the comment:

Hi Storchaka,

As per re.groups(), its should work as below:

groups([default])
Return a tuple containing all the subgroups of the match, from 1 up to however 
many groups are in the pattern. The default argument is used for groups that 
did not participate in the match; it defaults to None. (Incompatibility note: 
in the original Python 1.5 release, if the tuple was one element long, a string 
would be returned instead. In later versions (from 1.5.1 on), a singleton tuple 
is returned in such cases.)

For example:

>>> m = re.match(r"(\d+)\.(\d+)", "24.1632")
>>> m.groups()
('24', '1632')
If we make the decimal place and everything after it optional, not all groups 
might participate in the match. These groups will default to None unless the 
default argument is given:

>>> m = re.match(r"(\d+)\.?(\d+)?", "24")
>>> m.groups()      # Second group defaults to None.
('24', None)
>>> m.groups('0')   # Now, the second group defaults to '0'.
('24', '0')

I tested some scenario as below:
Scenario: Suppose i have a match like 
m = re.match(r"(\d+)\.(\d+)", "24.1632")
Here if i pass m.groups(10000), then it should check if there is optional match 
(optional match, pattern which is specified using ?), it should print 10000 in 
that match and if not, it should throw error that there is no any optional 
match (didn't have any pattern with ?).

Expected Output:
>>> m.groups(10000)
There is no any optional argument to use 10000

Received Output:
>>> m.groups(10000)
'24', '1632')

Please review the above and provide your comments?

----------
resolution: not a bug -> 
status: closed -> open

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31969>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to