Skip to content

Commit e8239b8

Browse files
authored
Add information about DeprecationWarning for invalid escaped characters in the re module (GH-5255)
1 parent b2dc4a3 commit e8239b8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Doc/library/re.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ character for the same purpose in string literals; for example, to match
2828
a literal backslash, one might have to write ``'\\\\'`` as the pattern
2929
string, because the regular expression must be ``\\``, and each
3030
backslash must be expressed as ``\\`` inside a regular Python string
31-
literal.
31+
literal. Also, please note that any invalid escape sequences in Python's
32+
usage of the backslash in string literals now generate a :exc:`DeprecationWarning`
33+
and in the future this will become a :exc:`SyntaxError`. This behaviour
34+
will happen even if it is a valid escape sequence for a regular expression.
3235

3336
The solution is to use Python's raw string notation for regular expression
3437
patterns; backslashes are not handled in any special way in a string literal

0 commit comments

Comments
 (0)