Python 3 interprets string literals as Unicode strings, and therefore \s and \g are treated as escaped Unicode characters. Fix: Declare RegEx pattern as a raw string instead by prepending r