I’m trying to write a little SQL Helper. I have a query like this stored in a string:
DECLARE @V1 INT
--ignore
DECLARE @V11 INT
DECLARE @V12 INT
--endignore
DECLARE @V2 INT
--ignore
SELECT * FROM SampleTable
INNER JOIN AnotherSampleTable
......
--endignore
SELECT * From Employee ORDER BY LastName
My helper method should cut everything what’s between
--ignore
and
--endignore
The result string should look like:
DECLARE @V1 INT
DECLARE @V2 INT
SELECT * From Employee ORDER BY LastName
How can achieve my result with RegEx?
Here’s a short example:
Note the use of RegexOptions.Singleline so that
.matches any character including\n.I’ve used Windows line separators here, but you could make the carriage returns optional if you want to be able to cope with Unix separators. I wanted to make sure that the tokens were on their own lines to avoid any rogue references within the SQL, even if that’s very unlikely.