import re
regex = re.compile(r"([\'\"])([^\\]|\\.(?#如果有转义字符,必然是成对出现))*?\1(?#匹配和前面相同的引号)", flags=re.MULTILINE | re.UNICODE)
test_str = "SELECT 'a', \"b\" from table where a = '这是\"一句\\\"断\\'了的话' And b <> '特别\"\"的\"\"\"结尾\\\\\\'\\\\' And c in ('单引号', \"双引号\") and d in ( select 'vv' from table_b ) ORDER BY table.id DESC limit 100,10"
subst = "?"
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