Four single-quotes in a row -- the first three terminated the string literal, the last one began a new string literal.
You would need to escape it, but as you may have noticed, the backslash stays in the string. This only happens because you are using a raw string literal -- using
Code:
html = re.sub('''<p>' ''', '''<p>\'''', html)
works as expected.
Raw string literals are useful for strings in which you expect to have literal backslashes. That does not apply here.
Double-quotes work too, of course.
If you need to use both single- and double-quotes, make sure to escape whatever your delimiter is.