import re
regex = re.compile(r"\(\s*/.*?/\w*\h*,(*SKIP)(*F)|(?|(\")[^\"\\]*(?:\\.[^\"\\]*)*\"|(')[^'\\]*(?:\\.[^'\\]*)*')")
test_str = ("Test\n"
"a=\"abc\";\n"
"b='def';\n"
"c=\"That's the way to do it\";\n"
"d='That\\'s the way \"to do it\"';\n"
"e=e.replace(//g, '\"');\n"
"f=f.replace(/'/g, '\"');\n"
"g=g.replace(/\\'/g, '\"');\n"
"h=h.replace(/\\\"/g, '\\\"');\n"
"i=i.replace(/\\\\\"/g, '\\\\\"');\n")
subst = "$1XXXX$1"
result = regex.sub(subst, test_str)
if result:
print(result)
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html