import retext = "('hel'lo') eq 'some 'variable he're'"print(re.compile(r"(?<!\()(?<!eq )'(?!\)|\Z)").sub(string=text, repl="''"))
Standard input is empty
('hel''lo') eq 'some ''variable he''re'
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!