import re
text = "('hel'lo') eq 'some 'variable he're'"
print(re.compile(r"(?<!\()(?<!eq )'(?!\)|\Z)").sub(string=text, repl="''"))