fork download
  1. import re
  2.  
  3. string = """This ain't funny, you know.
  4. But this escaped one (\") won't change."""
  5.  
  6. rx = re.compile(r'''(?<!\\)(["'])''')
  7.  
  8. string = rx.sub(r'\\\1', string)
  9. print(string)
Success #stdin #stdout 0s 23296KB
stdin
Standard input is empty
stdout
This ain\'t funny, you know.
But this escaped one (\") won\'t change.