About Patterns and the backslash \ character Goal: find pattern with \ in it First thought: use \ to escape \ x = re.search("a.\\y", "ab\y") blows up. Why? The pattern string is scanned twice -- first by the Python interpreter, next by the pattern matcher, so: "a.\\y" -- seen by Python interpreter; processed to "a.\y" "a.\y" -- seen by the Python pattern matcher; ERROR as \y is invalid So try this: x = re.search("a.\\\\y", "ab\y") That works. Note "\y" in the string is a backslash followed by a "y". That's because the Python interpreter looks for \ as part of an escape sequence. If it is, the \ and following character are processed into the special character. If not, it's treated as a backslash. That's why printing x gives you span=(0,4) Note in the match, x has match='ab\\y'; that's because the single \ prints as 2. We can see this as: x = 'ab\y' displaying x shows: 'ab\\y' but len(x) gives 4. Also, note if you do print(x), you get 'ab\y' Now, look at y = 'ab\t' and \t is an escape sequence (a tab). Then if you display y, you get 'ab\t' with len(y) is 3 as the \t is a tab (hex 0x9). There's another way -- using the "raw string" notation. That suppresses the processing by the Python interpreter. x = r'ab\y' is the same as x = 'ab\\y' Now watch this: y = 'ab\t' Now len(y) is 4 as the interpretation of \ as an escape is suppressed.