I’m using regular expression to parse stored procedures in order to modify them.
here is my sample text:
DECLARE @TempTable TABLE
(
TempID int IDENTITY PRIMARY KEY,
AMFID smallint,
AppModID smallint,
AppID tinyint,
ModID smallint,
FPID smallint,
URL varchar(100),
SortIndex smallint,
[AppName] varchar(100),
ModName varchar(100),
FPName varchar(100),
WUCData varchar(7000)
)
-- Fill the temp table
INSERT INTO @TempTable
(
AMFID,
AppModID,
AppID,
ModID,
FPID,
URL,
SortIndex,
[AppName],
ModName,
FPName,
WUCData
)
SELECT
siAppModFP.AMFID,
siAppModFP.AppModID,
siAppModule.AppID,
siAppModule.ModID,
siAppModFP.FPID,
siAppModFP.URL,
siAppModFP.SortIndex,
siApplication.[AppName],
siModule.ModName,
siFP.FPName,
dbo.funcGetAppModFPWUC(siAppModFP.AMFID)
FROM siApplication WITH (NOLOCK)
…
I just want to get this part:
DECLARE @TempTable TABLE
(
TempID int IDENTITY PRIMARY KEY,
AMFID smallint,
AppModID smallint,
AppID tinyint,
ModID smallint,
FPID smallint,
URL varchar(100),
SortIndex smallint,
[AppName] varchar(100),
ModName varchar(100),
FPName varchar(100),
WUCData varchar(7000)
)
Notice it might be repeated more than once. I want all declarations of temp tables in the text.
I used following regular pattern:
string re1 = "(Declare)( )(@)((?:[a-z][a-z0-9_]*))(\\s+)(Table)(\\s+)(\\(.*\\))";
Regex r = new Regex(re1, RegexOptions.Multiline | RegexOptions.IgnoreCase);
But it’s not working.
Any ideas?
You have to use
singlelinemode notmultilinemodeUse this
regexwithsinglelinemodeSo,it should be
try it here