import pyperclip, re text = pyperclip.paste() text = re.sub(r"(\{|\})",r"\\\1",text) pyperclip.copy(text)