re.error: Bad Escape Sequence

DeprecationWarning: invalid escape sequence '\d'

Quick Answer

You have an invalid escape sequence in a regular string. Use raw strings (r'...') for regex patterns so Python does not interpret backslashes.

Why This Happens

Python processes escape sequences before the regex engine. \d in a regular string is not recognized by Python. Raw strings pass backslashes unchanged.

The Problem

import re
pattern = '\d+\.\d+'

The Fix

import re
pattern = r'\d+\.\d+'  # Raw string

Step-by-Step Fix

  1. 1

    Use raw strings

    Prefix with r: pattern = r'\d+\s+\w+'.

  2. 2

    Double backslashes

    If raw strings are not possible, double each backslash.

  3. 3

    Check all patterns

    Search for re.compile/match/search/findall without raw strings.

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free