You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
561 B

import re
def escape_single_quotes(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
content = file.read()
# Escape single quotes inside string literals
content = re.sub(r"''", r"'", content)
content = re.sub(r"(`[^`]*`)", r"'\1'", content)
content = re.sub(r"'`([^`]*)`'", r"'\1'", content)
content = re.sub(r"\'", r"''", content)
with open(file_path, 'w', encoding='utf-8') as file:
file.write(content)
# Usage
escape_single_quotes("/home/key/git/countries-states-cities-database/sql/world.sql")