I have problem with cleaning comments and empty lines from already existing sql file. The file has over 10k lines so cleaning it manually is not an option.
I have a litt
# Remove comments i.e. lines beginning with whitespace and '--' (using multi-line flag)
re.sub('^\s*--.*\n?', '', query, flags=re.MULTILINE)
Regex string explained:
"When specified, the pattern character '^' matches at the beginning of the string and at the beginning of each line (immediately following each newline)"
See the Python regular expressions documentation for more details:
https://docs.python.org/3/library/re.html