Notepad++ snippets
How to add code previous and next to a list of items in Notepad++
Let say you have the following list of temporary tables in SQL:
#Temp_Table_1
#Temp_Table_2
#Temp_Table_3
#Temp_Table_4
#Temp_Table_5
and you want transform them into the following:
IF OBJECT_ID('tempdb..#Temp_Table_1') IS NOT NULL DROP TABLE #Temp_Table_1
IF OBJECT_ID('tempdb..#Temp_Table_2') IS NOT NULL DROP TABLE #Temp_Table_2
IF OBJECT_ID('tempdb..#Temp_Table_3') IS NOT NULL DROP TABLE #Temp_Table_3
IF OBJECT_ID('tempdb..#Temp_Table_4') IS NOT NULL DROP TABLE #Temp_Table_4
IF OBJECT_ID('tempdb..#Temp_Table_5') IS NOT NULL DROP TABLE #Temp_Table_5
To do this in Notepad++, you can just hit CTRL
+ H
for Replace window and the select the following:
- Find what: (#)(.*)
- Replace with: IF OBJECT_ID\('tempdb..${0}\'\) IS NOT NULL DROP TABLE ${0}
- Flag Regular expression
- Do not flag . matches new lines