Regex to remove comments from SQL Stored Procedure



SQL Remove comments


The following regex expression
/\/\*[\s\S]*?\*\/|([^:]|^)--.*$/gm
removes following comments:
1. Code block inside /* */
2. Rest of line --

In javascript you can simply do
return sql_string.replace(/\/\*[\s\S]*?\*\/|([^:]|^)--.*$/gm,'');

Σχόλια

Δημοφιλείς αναρτήσεις