From c2301730b8e07ece0b7c4ff6b6b06a4895d370c7 Mon Sep 17 00:00:00 2001 From: Fredrik Lundh Date: Sun, 2 Jul 2000 22:25:39 +0000 Subject: - 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. --- Lib/sre_compile.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'Lib/sre_compile.py') diff --git a/Lib/sre_compile.py b/Lib/sre_compile.py index e5c501edd1..36986eb3e5 100644 --- a/Lib/sre_compile.py +++ b/Lib/sre_compile.py @@ -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 ) -- cgit v1.2.1