From 9a80e00cac40dd64709919c29386d8ede39f91d6 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Fri, 21 Aug 1998 18:39:38 +0000 Subject: [PATCH] The .subn() method wasn't setting _num_regs, which is used by the .groups() method, so .groups() didn't work inside the replacement function called by re.sub. One-line fix: set self._num_regs inside subn(). --- Lib/re.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/re.py b/Lib/re.py index dce29ceac99..d190363df47 100644 --- a/Lib/re.py +++ b/Lib/re.py @@ -167,6 +167,7 @@ class RegexObject: regs = match(source, pos, end, 0) if not regs: break + self._num_regs = len(regs) i, j = regs[0] if i == j == lastmatch: # Empty match adjacent to previous match