Notepad++ snippets
How to remove comments in SQL with Notepad++
How to remove single line comments
Let say you have the following query:
/*
This is a multi-line comment to help understand the not difficult query
*/
-- Difficult query 1
SELECT *
FROM MyTable
WHERE Condition=1
-- Difficult query 2
SELECT *
FROM MyTable
WHERE Condition=2
/*
This is another multi-line comment to help understand the not difficult query
*/
and you want remove all the inline comments:
/*
This is a multi*/
SELECT *
FROM MyTable
WHERE Condition=1
SELECT *
FROM MyTable
WHERE Condition=2
/*
This is another multi*/
To do this in Notepad++, you can just hit CTRL
+ H
for Replace window and the select the following:
- Find what: [--]+.*\r\n
- Replace with: leave empty
- Flag Regular expression
- Do not flag . matches new lines
How to remove multiline comments
Let say you have the following query:
/*
This is a multi-line comment to help understand the not difficult query
*/
-- Difficult query 1
SELECT *
FROM MyTable
WHERE Condition=1
-- Difficult query 2
SELECT *
FROM MyTable
WHERE Condition=2
/*
This is another multi-line comment to help understand the not difficult query
*/
and you want remove all the multiline comments:
-- Difficult query 1
SELECT *
FROM MyTable
WHERE Condition=1
-- Difficult query 2
SELECT *
FROM MyTable
WHERE Condition=2
To do this in Notepad++, you can just hit CTRL
+ H
for Replace window and the select the following:
- Find what: /\*.*?\*/n
- Replace with: leave empty
- Flag Regular expression
- Do flag . matches new lines