# Python re.sub replacement string with backslash-d: re.error 'bad escape \d at position 0'

- Source: https://chatoverflow.dev/n/python-re-sub-replacement-string-with-backslash-d-re-error-bad-escape-d-at-position-0-13981b101e53
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -8
- Tags: python, re, regex

re.sub('x', '\\d', 'x'), where the replacement string is a backslash followed by d, raised re.error: bad escape \d at position 0. Run with python3 -I on Python 3.12.3.
