简体   繁体   English

Notepad++ 正则表达式查找并删除一行

[英]Notepad++ Regular expression find and delete a line

I am trying to find and delete a line using Notepad++我正在尝试使用 Notepad++ 查找和删除一行

I need to find lines in this file (UNIX Format) that match the string ' #RedirectMatch Permanent ' and delete that line.我需要在此文件(UNIX 格式)中找到与字符串' #RedirectMatch Permanent '匹配的行并删除该行。

Does anyone know how to do this using Notepad++ Find and Replace?有谁知道如何使用 Notepad++ 查找和替换来执行此操作?

Thanks and Kind Regards,感谢和亲切的问候,

Step 1步骤1

  • SearchFind → (goto Tab) Mark SearchFind → (goto Tab) Mark
  • Find what : ^Session.*$ Find what :^Session.*$
  • Enable the checkbox Bookmark line启用复选框Bookmark line
  • Enable the checkbox Regular expression (under Search Mode )启用复选框Regular expression (在Search Mode
  • Click Mark All (this will find the regex and highlights all the lines and bookmark them)单击Mark All (这将找到正则表达式并突出显示所有行并将它们添加为书签)

Step 2第2步

  • SearchBookmarkRemove Bookmarked Lines SearchBookmarkRemove Bookmarked Lines

If it supports standard regex...如果它支持标准正则表达式...

find:
^.*#RedirectMatch Permanent.*$

replace:

Replace with nothing.什么都不换。

Provide the following in the search dialog:在搜索对话框中提供以下内容:

Find What: ^$\r\n查找内容: ^$\r\n
Replace With: (Leave it empty)替换为:(留空)

Click Replace All单击全部替换

Combining the best from all the answers结合所有答案中最好的

在此处输入图像描述

Using the "Replace all" functionality, you can delete a line directly by ending your pattern with :使用“全部替换”功能,您可以通过以以下方式结束您的模式来直接删除一行:

  • If your file have linux (LF) line ending: $\n?如果您的文件有 linux (LF) 行结尾: $\n?
  • If your file have windows (CRLF) line ending: $(\r\n)?如果您的文件有 Windows (CRLF) 行结尾: $(\r\n)?

For instance, in your case:例如,在您的情况下:

.*#RedirectMatch Permanent.*$\n?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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