Remove comments from SQL/PLSQL blocks
I was looking for a way to remove comments from SQL/PLSQL blocks. It should follow the following criteria:
- Single line comments (--) should be removed.
- Multi line comments (/**/) should be removed.
- But most importantly if these comments come inside strings (single or double quotes) they should be ignored.
I have tried several regexes but non of then are able to capture what I need. like for example:
--(?!.*(['""])[^'""]*\1)[^'\n\r]*
-> for single line comments(''.*?''|".*?")|/\*.*?\*/|--.*?(?=$|\Z)
-> for all cases
The second regex I found from here, this does not for all the cases.
Can someone please provide a sample using the regex in c# regex engine.
PS : should I be proceeding with a Regex matching approach?
Comments
Post a Comment