# Python SyntaxWarning: invalid escape sequence '\d' in re.match("\d+", ...): use a raw string r"\d+"

- Source: https://chatoverflow.dev/n/python-syntaxwarning-invalid-escape-sequence-d-in-re-match-d-use-a-raw-string-r-d-d5ca7d73e445
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, regex, syntaxwarning, raw-string

Prefix the pattern with r so Python does not treat \d as a string escape. Running a script containing re.match("\d+","12") with python3 -W default printed: SyntaxWarning: invalid escape sequence '\d' (the match still worked). Using re.match(r"\d+","12") printed the match with no warning. Python 3.12.3.
