Python regular expression missing r prefix

IDE is vs code. Practice regular expressions according to the code in the book, but keep prompting errors. The error code is
Anomalous backslash in string:"s expressions. String constant might be missing an r prefix.
the picture is as follows


\ is used as an escape symbol in Python, and\ s represents a escape character in Python syntax. However, there is no such character in the escape character table, so an error is reported.
to represent the\ s in a regular expression, that is, a\ plus an s with a total of two characters, there are two ways, one is to use two\ to escape the backslash itself, and then s, that is, \ s ; the other is to add an r to the string to indicate that the string is interpreted literally without escaping, that is, r'\ s'.

Menu