]> granicus.if.org Git - python/commitdiff
The .subn() method wasn't setting _num_regs, which is used by the .groups()
authorAndrew M. Kuchling <amk@amk.ca>
Fri, 21 Aug 1998 18:39:38 +0000 (18:39 +0000)
committerAndrew M. Kuchling <amk@amk.ca>
Fri, 21 Aug 1998 18:39:38 +0000 (18:39 +0000)
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

index dce29ceac9921dd2592658b3220d7b1135e6b069..d190363df47581c0c0478b0d738749a5f1749e4b 100644 (file)
--- 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