score:111

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:

re.compile(r"\d{3}")

or escape backslash explicitly:

re.compile("\\d{3}")

score:5

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