Accepted answer

"\d" is same as "\\d" because there's no escape sequence for d. but it is not clear for the reader of the code.

but, consider \t. "\t" represent tab chracter, while r"\t" represent literal \ and t character.

so use raw string when you mean literal \ and d:


or escape backslash explicitly:



python is unable to parse '\d' as an escape sequence, that's why it produces a warning.

after that it's passed down to regex parser literally, works fine as an e.s. for regex.

Related Query