I want to generate dynamic sql on Notepad++ based on some rules. These rules include everything, so no sql knowledge is needed, and are the following:
- Dynamic sql must have each single quote escaped by another single quote ( 'hello' becomes ''hello'')
- Each line should begin with "+@lin"
- If a line has only whitespace, nothing should be following the "+@lin", despite following rules
- Replace each \t directly following "+@lin" with "+@tab"
- Add " +' " after the @lin/@tab sequence
- Add a single quote at the end of line
So, as an example, this input:
select 1,'hello'
from --two tabs exist after from
table1
should become:
+@lin+'select 1,''hello'''
+@lin+'from --two tabs exist after from'
+@lin
+@lin+@tab+'table1'
What I have for now is the following 4 steps:
- Replace single quote with double quotes to cover rule 1
- Replace
^(\t*)(.*)$
with\+@lin\1\+'\2'
to cover rules 2,5,6 - Replace
\t
with\+@tab
to cover rule 4 - Replace
(\+@tab)*\+''$
with nothing to cover rule 3
Notice that this mostly works, except for the third replacement, which replaces all tabs, and not only the ones at the beginning. I tried (?<=^\t*)\t
with no success- it matches nothing.
I'm looking for a solution which satisfies the rules in as few replacement steps as possible.