繁体   English   中英

在npp中的正则表达式查找在一个词之后(包括一个词直到另一个词)的所有内容

[英]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开头的行,否则可能会更改其他单词。我不知道如何执行仅执行此操作的惰性正则表达式,我们将不胜感激。

认为您要: AS[\\d\\D]*?(?=SELECT) 在此处输入图片说明

您可以在此处查看演示。 https://regex101.com/r/IFNqbG/3

  • Ctrl + H
  • 查找内容: (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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM