Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c30faa8 commit 3554cadCopy full SHA for 3554cad
1 file changed
Lib/test/test_re.py
@@ -235,6 +235,16 @@ def test_re_groupref_exists(self):
235
self.assertEqual(re.match('^(?:(a)|c)((?(1)|d))$', 'a').groups(),
236
('a', ''))
237
238
+ # Tests for bug #1177831: exercise groups other than the first group
239
+ p = re.compile('(?P<g1>a)(?P<g2>b)?((?(g2)c|d))')
240
+ self.assertEqual(p.match('abc').groups(),
241
+ ('a', 'b', 'c'))
242
+ self.assertEqual(p.match('ad').groups(),
243
+ ('a', None, 'd'))
244
+ self.assertEqual(p.match('abd'), None)
245
+ self.assertEqual(p.match('ac'), None)
246
+
247
248
def test_re_groupref(self):
249
self.assertEqual(re.match(r'^(\|)?([^()]+)\1$', '|a|').groups(),
250
('|', 'a'))
0 commit comments