mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
- experimental: added two new attributes to the match object:
"lastgroup" is the name of the last matched capturing group, "lastindex" is the index of the same group. if no group was matched, both attributes are set to None. the (?P#) feature will be removed in the next relase.
This commit is contained in:
parent
c9c02c4cf3
commit
c2301730b8
4 changed files with 38 additions and 13 deletions
|
@ -298,8 +298,14 @@ def compile(p, flags=0):
|
|||
assert p.pattern.groups <= 100,\
|
||||
"sorry, but this version only supports 100 named groups"
|
||||
|
||||
# map in either direction
|
||||
groupindex = p.pattern.groupdict
|
||||
indexgroup = [None] * p.pattern.groups
|
||||
for k, i in groupindex.items():
|
||||
indexgroup[i] = k
|
||||
|
||||
return _sre.compile(
|
||||
pattern, flags,
|
||||
array.array(WORDSIZE, code).tostring(),
|
||||
p.pattern.groups-1, p.pattern.groupdict
|
||||
p.pattern.groups-1, groupindex, indexgroup
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue