The double-escape problem
In Python strings, the backslash \ is the escape character. '\n' is a newline; '\t' is a tab; '\b' is the ASCII bell.
In regex patterns, the backslash is ALSO the escape character. \d is a digit; \b is a word boundary; \. is a literal dot.
Without raw strings, you'd have to write '\\d' for the regex digit class — one backslash for Python's string parser, another for regex. Annoying and error-prone.
Raw strings disable Python's interpretation
Prefix a string literal with r: r'\d+'. Now Python doesn't interpret backslashes — they pass through to regex unchanged. r'\b\w+\b' means exactly what it looks like.
The bug class without raw strings
'\b' in Python is the ASCII bell character (chr(8)). If you write re.search('\bword', text), Python sees '\x08word' as the pattern — definitely not what you wanted. Some patterns happen to work without raw strings ('\d' isn't a valid Python escape so it stays as two chars), but relying on this is fragile.
Always use raw strings for regex patterns in Python. No exceptions.
F-strings for dynamic patterns
To interpolate variables, combine raw and f-string: rf'\b{word}\b'. Or use re.escape when interpolating user input: rf'\b{re.escape(word)}\b'.