我有一个包含大量SQL的文件,包括一些存储过程。我只想提取存储过程。 SQL可能如下所示
SHOW PROCEDURE SECADMIN.NewTUTRMU_User_new ;
3 Rows returned. DBS time = 00:00:00
RequestText
REPLACE PROCEDURE SecAdmin.NewTUTRMU_User_new
(
IN UserName VARCHAR(128),
IN SARNumber VARCHAR(10),
)
/*
come comments
*/
BEGIN
DECLARE emOwnerDeptI VARCHAR(20);
SEL SUBSTRING(:UserName FROM 8) INTO :GDWUserid;
CALL DBC.SysExecSql('
CREATE USER '||:UserName||' ...
...
...
END;
...
Then some more SQL and then another stored procedure definition
...
SHOW PROCEDURE SECADMIN.ReInstateUser_new ;
3 Rows returned. DBS time = 00:00:00
RequestText
REPLACE PROCEDURE SECADMIN.ReInstateUser_new
(
IN UserName VARCHAR(128)
--Must be full employee ID including leading 0's
,IN Empl_I VARCHAR(12),
IN Task_Num )
/*
MODIFICATION HISTORY:
*/
BEGIN
DECLARE newPassword VARCHAR(20);
...
...
END;
...
...
我提出了以下RegEx,它不起作用并匹配文本,直到找到分号。
REPLACE PROCEDURE.*[^;]*;
我需要一个与REPLACE PROCEDURE到END;
的文本匹配的正则表达式请建议。
答案 0 :(得分:1)
根据提供的示例,我认为这样做:/REPLACE PROCEDURE [\w\W]+?END;/g
以下是测试:http://refiddle.com/refiddles/5626e70d75622d65a0250000