May-30-2018, 11:29 AM
Hi
I cannot work out why the following works:
Thanks
I cannot work out why the following works:
import re text = "Follow up on the new sales *order*. Do not consider the cancelled *order*" pattern = re.compile(r'\*(.*?)\*') print("Before substitution: ", text) text = pattern.sub(r"<b>\g<1><\\b>", text) print("After substitution: ", text)but the following generates a "bad escape \g" error:
import re text = "Follow up on the new sales *order*. Do not consider the cancelled *order*" pattern = re.compile(r'\*(.*?)\*') print("Before substitution: ", text) transform_pattern = re.compile(r"<b>\g<1><\\b>") text = pattern.sub(transform_pattern, text) print("After substitution: ", text)Any suggestions?
Thanks