Regular Expression pattern group
john.hsu at sovereign.co.nz
Thu Jun 15 08:13:59 CEST 2006
I am a fussy learner. Could someone explain to me why the following
inconsistency exists between methods? How can it be justified if it is
considered all right?
There are three groups in pattern. However, match object shows 3 groups
in collection, but group has to be indexed from one because the
m.group(0) is the implicit group for whole pattern.
Are these just some things to remember? "Group counting is from one".
>>> p = sre.compile('abc(.(.).)d(ef)')
>>> m = p.search(s)
('???', '?', 'ef')
Traceback (most recent call last):
File "<pyshell#279>", line 1, in -toplevel-
IndexError: no such group
[('???', '?', 'ef')]
More information about the Python-list