Notepad ++使用特定关键字

时间:2015-07-12 12:14:40

标签: regex notepad++

The camel is walking on water.
The cow jumped over the fence
The dog couldn't jump over the fence
The chicken flew over the ocean
The rabbit ate the elephant
The goat is singing like a bird
The dog barks like a woman

我有一个很长的列表,我需要删除上面的两行,如果我找到单词" dog"连续。所以最终的结果应该是

The dog couldn't jump over the fence
The chicken flew over the ocean
The dog barks like a woman

请让我知道如何完成这件事:)谢谢!!

1 个答案:

答案 0 :(得分:0)

输入

The camel is walking on water.
The cow jumped over the fence
The dog couldn't jump over the fence
The chicken flew over the ocean
The rabbit ate the elephant
The goat is singing like a bird
The dog barks like a woman

查找和替换 - 在正则表达式模式下

查找内容:.*\r\n.*\r\n(.*dog.*)
替换为:\1

结果

The dog couldn't jump over the fence
The chicken flew over the ocean
The dog barks like a woman

解释

.*匹配任何字符 - 零到无限次(换行除外)
\r\n一起代表换行符
(.*dog.*)表示包含“dog”的行,整行被捕获到\1

在找到3条这样的线条之后,然后用包含狗的线替换所有三条线。

注意:这将删除包含“dog”的任何行上方的两行,即使其中一行本身包含“dog”