记事本++ - 搜索并替换一个词并删除行

notepad++ - search and replace for a word and remove line

希望我能让大家理解:

就说我在文件中有这段文字:

bash-4.2$ 336
1
bash-4.2$ 401
2
bash-4.2$ 403
3
bash-4.2$ 404
4
bash-4.2$ 735
5
bash-4.2$ 894
6
bash-4.2$ 909
7

我想删除以 "bash" 开头的行中的所有内容,因此我正在寻找此输出:

1
2
3
4
5
6
7

我一直在使用正则表达式搜索(在 https://regex101.com/r/kT0uE3/1 的帮助下),如果我使用这个搜索 "bash.*" 它会删除行而不是回车 return。

当我将此搜索更改为 "bash.*\n" 时,它没有找到任何内容(尽管 regex101 说它会起作用)。

我想我遗漏了一些明显而简单的东西,但我只见树木不见森林。

非常感谢任何帮助。

  • Ctrl+H
  • 查找内容:^bash-.+\R
  • 替换为:LEAVE EMPTY
  • 检查 匹配大小写
  • 检查 环绕
  • 检查 正则表达式
  • 取消选中 . matches newline
  • 全部替换

解释:

^           # beginning of line
  bash-     # literally
  .+        # 1 or more any character but newline
  \R        #any kind of linebreak

屏幕截图(之前):

截图(后):