Issues #814253, #9179: Group references and conditional group references now
work in lookbehind assertions in regular expressions.
diff --git a/Lib/re.py b/Lib/re.py
index bc3056f..788fa6b 100644
--- a/Lib/re.py
+++ b/Lib/re.py
@@ -351,10 +351,11 @@
         s = sre_parse.Pattern()
         s.flags = flags
         for phrase, action in lexicon:
+            gid = s.opengroup()
             p.append(sre_parse.SubPattern(s, [
-                (SUBPATTERN, (len(p)+1, sre_parse.parse(phrase, flags))),
+                (SUBPATTERN, (gid, sre_parse.parse(phrase, flags))),
                 ]))
-        s.groups = len(p)+1
+            s.closegroup(gid, p[-1])
         p = sre_parse.SubPattern(s, [(BRANCH, (None, p))])
         self.scanner = sre_compile.compile(p)
     def scan(self, string):