Regex to remove single-line SQL comments (--)

前端 未结 7 1072
悲哀的现实
悲哀的现实 2021-01-15 08:52

Question:

Can anybody give me a working regex expression (C#/VB.NET) that can remove single line comments from a SQL statement ?

I mean these comments:

7条回答
  •  无人及你
    2021-01-15 09:16

    You want something like this for the simple case

    -{2,}.*
    

    The -{2,} looks for a dash that happens 2 or more times

    The .* gets the rest of the lines up to the newline

    *But, for the edge cases, it appears that SinistraD is correct in that you cannot catch everything, however here is an article about how this can be done in C# with a combination of code and regex.

提交回复
热议问题