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:

  1. Single line comments (--) should be removed.
  2. Multi line comments (/**/) should be removed.
  3. 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. --(?!.*(['""])[^'""]*\1)[^'\n\r]* -> for single line comments
  2. (''.*?''|".*?")|/\*.*?\*/|--.*?(?=$|\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

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation