I have the following regex:
Regex defineProcedureRegex = new Regex(@"\s*(\bcreate\b\s+\bprocedure\b\s+(?:|dbo\.))(\w+)\s+(?:|(.+?))(as\s+(?:.+?)\s+\bgo\b)\s*", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.RightToLeft | RegexOptions.Singleline);
that I am running against a SQL script file containing multiple "create procedure" statements. The format of the file is like this:
use databasename
create procedure dbo.procedure_name
@param1 varchar(10) -- optional
as
-- do stuff
go
use databasename
create procedure dbo.another_procedure
@param1 varchar(10) -- optional
as
-- do other stuff
go
The problem I have is that I need to match the first as
, but only the last go
. Since the procedure body may also contain as
and go
(within comments), I can't figure out how to do this reliably.
Any help/comments/advice?