我的文本中带有SAS代码。本质上,它是在
之间包装的SQL查询 PROC SQL;
.
.
.
.
.
QUIT;
我试图将两者之间的SQL提取为单个匹配项。
这是我的文本文件的外观
***logic 1***
proc sql;
create table Combined as
select t1.name, t2.units
from mdweop.candy_customers_azim_056 as t1
inner join mdweop.candy_sales_history_set t2 on (t1.custid = t2.ORIGTN_ACCT_NO);
quit;
***logic 2***
PROC SQL;
CREATE TABLE COMBINED AS
SELECT T1.RPOG_HMDA_CODES, T2.RSN_DECL1_C
FROM MDWEOP.CANDY_CUSTOMERS AS T1
INNER JOIN MDWEOP.CANDY_SALES_HISTORY AS T2
ON (T1.CUSTID = T2.ACA_MISC_Z03HMDA_BV);
QUIT;
***logic 3***
PROC SQL;
CREATE TABLE COMBINED AS
SELECT T1.RRG_PRPS_CODES, T2.RSN_DECL1_C
FROM MDWEOP.CANDY_CUSTOMERS AS T1
INNER JOIN MDWEOP.CANDY_SALES_HISTORY AS T2
ON (T1.CUSTID = T2.ACA_MISC_Z03HMDA_BV);
QUIT;
我尝试了这个regex,但它发现每一行都是单个匹配项。
理想情况下,如果我想从文本文件中提取每个SQL查询
任何潜在客户都很受赞赏。
答案 0 :(得分:1)
我怀疑这是否可以解决您真正的问题以获得SQL?,但是我已经按照您的正则表达式演示发布了此答案。
const regex = /START-OF-FIELDS[\r\n]+(.*)[\n\r]+(.*)[\n\r](.*)[\n\r]END-OF-FIELDS/img;
const str = `START-OF-FIELDS
Line A
Line B
Line C
END-OF-FIELDS`;
let m;
const sql_lines = []
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
if (groupIndex > 0) {
sql_lines.push(match);
}
});
}
console.log(sql_lines)
答案 1 :(得分:1)
您可以在正则表达式中添加s
修饰符,以使.
字符也可以匹配换行符,而i
可以匹配大小写。还可以使用非捕获组作为前缀和后缀:
/^(?:START\-OF\-FIELDS)(.*)(?:END\-OF\-FIELDS)$/mgsi