
[英]regex to find content from occurrance of word and not including the word until a char
[英]Regex in npp to find everything after and including a word until another word
我试图生成一个正则表达式以在AS之后捕获任何东西(包括换行符),直到SELECT删除AS。 有多种变体,每当有一次插入时,我都想重复。 有些根本没有AS,什么也不做。
INSERT OVERWRITE schema.table1
AS
SELECT
INSERT OVERWRITE schema.table2
AS -- (some spaces sometimes here)
SELECT
我只想删除以AS开头的行,否则可能会更改其他单词。我不知道如何执行仅执行此操作的惰性正则表达式,我们将不胜感激。
您可以在此处查看演示。 https://regex101.com/r/IFNqbG/3
(INSERT\\b.*?\\R)AS.*?\\R(?=SELECT\\b)
$1
说明:
( : start group 1
\bINSERT\b : literally 'INSERT', with word boundaries to not match 'INSERTED' for instance
.*? : 0 or more anycharacter, not greedy
\R : any kind of linebreak
) : end group 1
AS\b : literally 'AS', with word boundary to not match 'ASSIGN' for instance
.*? : 0 or more anycharacter, not greedy
\R : any kind of linebreak
(?=SELECT\b) : lookahead, make sure we have SELECT after but not SELECTED
. matches newline
如果INSERT或AS行可以在多行上,则. matches newline
行 替代:
$1 : group 1
给定示例的结果:
INSERT OVERWRITE schema.table1
SELECT
INSERT OVERWRITE schema.table2
SELECT
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.