mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Closes #14462: allow any valid Python identifier in sre group names, as documented.
This commit is contained in:
parent
991fc5736e
commit
1d472b74cb
2 changed files with 24 additions and 4 deletions
|
@ -180,6 +180,10 @@ class ReTests(unittest.TestCase):
|
|||
self.assertRaises(re.error, re.compile, '(?(a))')
|
||||
self.assertRaises(re.error, re.compile, '(?(1a))')
|
||||
self.assertRaises(re.error, re.compile, '(?(a.))')
|
||||
# New valid/invalid identifiers in Python 3
|
||||
re.compile('(?P<µ>x)(?P=µ)(?(µ)y)')
|
||||
re.compile('(?P<𝔘𝔫𝔦𝔠𝔬𝔡𝔢>x)(?P=𝔘𝔫𝔦𝔠𝔬𝔡𝔢)(?(𝔘𝔫𝔦𝔠𝔬𝔡𝔢)y)')
|
||||
self.assertRaises(re.error, re.compile, '(?P<©>x)')
|
||||
|
||||
def test_symbolic_refs(self):
|
||||
self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<a', 'xx')
|
||||
|
@ -192,6 +196,10 @@ class ReTests(unittest.TestCase):
|
|||
self.assertRaises(re.error, re.sub, '(?P<a>x)|(?P<b>y)', '\g<b>', 'xx')
|
||||
self.assertRaises(re.error, re.sub, '(?P<a>x)|(?P<b>y)', '\\2', 'xx')
|
||||
self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<-1>', 'xx')
|
||||
# New valid/invalid identifiers in Python 3
|
||||
self.assertEqual(re.sub('(?P<µ>x)', r'\g<µ>', 'xx'), 'xx')
|
||||
self.assertEqual(re.sub('(?P<𝔘𝔫𝔦𝔠𝔬𝔡𝔢>x)', r'\g<𝔘𝔫𝔦𝔠𝔬𝔡𝔢>', 'xx'), 'xx')
|
||||
self.assertRaises(re.error, re.sub, '(?P<a>x)', r'\g<©>', 'xx')
|
||||
|
||||
def test_re_subn(self):
|
||||
self.assertEqual(re.subn("(?i)b+", "x", "bbbb BBBB"), ('x x', 2))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue