Notepad++ 删除具有特定关键字的行上方的 2 行
Notepad++ Delete 2 rows above the row with a specific keyword
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",我需要删除上面的 2 行。所以最终结果应该是
The dog couldn't jump over the fence
The chicken flew over the ocean
The dog barks like a woman
请告诉我如何完成这项工作:)谢谢!!
输入
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.*)
替换为:</code></p>
<h3>结果</h3>
<pre><code>The dog couldn't jump over the fence
The chicken flew over the ocean
The dog barks like a woman
说明
.*
匹配任何字符 - 零次到无限次(换行符除外)
\r\n
一起代表一个换行符
(.*dog.*)
表示包含 "dog" 的一行,整行被捕获到
找到 3 条这样的行后,将所有这三行替换为包含 dog 的行。
注意:这将删除任何包含 "dog" 的行上方的两行,即使其中一行本身包含 "dog"
怎么样:
键入 Ctrl+H 然后,
查找内容:(?:.+\R){2}(?=.+?\bdog\b)
替换为:NOTHING
确保您已选中 Regular Expression
但未选中 dot matches newline
。
然后点击Replace all
解释:
(?: : Start NON capture group
.+ : One or more any character
\R : any type of newline
){2} : this group must occur twice
(?= : Positive lookahead
.+? : One or more any character (non greedy)
\bdog\b : the word dog alone (ie. not mydog or doggy)
) : end of lookahead
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",我需要删除上面的 2 行。所以最终结果应该是
The dog couldn't jump over the fence
The chicken flew over the ocean
The dog barks like a woman
请告诉我如何完成这项工作:)谢谢!!
输入
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.*)
替换为:</code></p>
<h3>结果</h3>
<pre><code>The dog couldn't jump over the fence
The chicken flew over the ocean
The dog barks like a woman
说明
.*
匹配任何字符 - 零次到无限次(换行符除外)
\r\n
一起代表一个换行符
(.*dog.*)
表示包含 "dog" 的一行,整行被捕获到
找到 3 条这样的行后,将所有这三行替换为包含 dog 的行。
注意:这将删除任何包含 "dog" 的行上方的两行,即使其中一行本身包含 "dog"
怎么样:
键入 Ctrl+H 然后,
查找内容:(?:.+\R){2}(?=.+?\bdog\b)
替换为:NOTHING
确保您已选中 Regular Expression
但未选中 dot matches newline
。
然后点击Replace all
解释:
(?: : Start NON capture group
.+ : One or more any character
\R : any type of newline
){2} : this group must occur twice
(?= : Positive lookahead
.+? : One or more any character (non greedy)
\bdog\b : the word dog alone (ie. not mydog or doggy)
) : end of lookahead