Skip to content

Commit fe8e6e7

Browse files
committed
#13899: \A, \Z, and \B now correctly match the A, Z, and B literals when used inside character classes (e.g. [A]). Patch by Matthew Barnett.
1 parent 26ed234 commit fe8e6e7

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

Lib/sre_parse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def _class_escape(source, escape):
235235
if code:
236236
return code
237237
code = CATEGORIES.get(escape)
238-
if code:
238+
if code and code[0] == IN:
239239
return code
240240
try:
241241
c = escape[1:2]

Lib/test/test_re.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,12 @@ def test_compile(self):
857857
# Test behaviour when not given a string or pattern as parameter
858858
self.assertRaises(TypeError, re.compile, 0)
859859

860+
def test_bug_13899(self):
861+
# Issue #13899: re pattern r"[\A]" should work like "A" but matches
862+
# nothing. Ditto B and Z.
863+
self.assertEqual(re.findall(r'[\A\B\b\C\Z]', 'AB\bCZ'),
864+
['A', 'B', '\b', 'C', 'Z'])
865+
860866
@bigmemtest(size=_2G, memuse=character_size)
861867
def test_large_search(self, size):
862868
# Issue #10182: indices were 32-bit-truncated.

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Chris Barker
6565
Anton Barkovsky
6666
Nick Barnes
6767
Quentin Barnes
68+
Matthew Barnett
6869
Richard Barran
6970
Cesar Eduardo Barros
7071
Des Barry

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ Core and Builtins
199199
Library
200200
-------
201201

202+
- Issue #13899: \A, \Z, and \B now correctly match the A, Z, and B literals
203+
when used inside character classes (e.g. '[\A]'). Patch by Matthew Barnett.
204+
202205
- Issue #15545: Fix regression in sqlite3's iterdump method where it was
203206
failing if the connection used a row factory (such as sqlite3.Row) that
204207
produced unsortable objects. (Regression was introduced by fix for 9750).

0 commit comments

Comments
 (0)