notepad ++:递归地保存2个关键字之间的任何内容?

时间:2014-02-28 13:26:03

标签: regex notepad++

如何在两个关键字之间保留任何文本并递归删除其他部分?

注意:一行的开头是以关键字开头。

示例:

some text
Keyword1
      More text
Keyword2
some text
Keyword1
      More text
Keyword2
some text
(note : the sequence Keyword1/More text/Keyword2 is repeated more than 200 times)
some text
Keyword1
      More text
Keyword2
some text

结果:

Keyword1
      More text
Keyword2
Keyword1
      More text
Keyword2
(note : the sequence Keyword1/More text/Keyword2 is repeated more than 200 times)
Keyword1
      More text
Keyword2

我在remove anything after this string END_PAGEREFS and remove anything before BEGIN_PAGEREFS找到了我需要在关键字后添加“。*”。但它不起作用。 ;(

注意:我已完成此操作:将“Keyword1。”“”替换为“Keyword2。*” 我检查过:“环绕”和“正则表达” 如果我选择了正确的关键字,我还使用Find + Count进行了检查。他们似乎对我不对。

以下是我尝试过的一些照片: 之前: Before

点击“全部替换”后:

After

提前致谢;) 编辑:我已更新我的示例,因为我实际上有200多个关键字1 /更多text / keyword2的序列。

1 个答案:

答案 0 :(得分:1)

你想做什么,就是检查'。匹配换行符'然后输入以下内容:

Find what: Keyword2.*?Keyword1

Replace with:Keyword2\nKeyword1

这样,你就无需更换两个关键字之间的所有内容。 这只是让您找到第一个Keyword1以及最后Keyword2之后的所有内容。