re.group vs re.groups

Huaiyu Zhu huaiyu at gauss.almadan.ibm.com
Wed Oct 10 20:01:06 EDT 2001


Hi, I'm puzzled by the behavior of the group and groups attributes of the re
match objects.  Why would b.group(0) below return the entire match string?

Python 2.1 (#1, Oct  2 2001, 15:35:43) 
[GCC 2.95.2 19991024 (release)] on linux2
>>> import re
>>> start = re.compile("^\[(\d{4})\] ")
>>> b = start.match ("[0256] ")
>>> b
<SRE_Match object at 0x80d8658>
>>> b.group()
'[0256] '
>>> b.group(0)
'[0256] '
>>> b.groups(0)
('0256',)
>>> b.groups()
('0256',)
>>> b.groups()[0]
'0256'

Huaiyu




More information about the Python-list mailing list