Notepad++ Regular expression find and delete a line

RegexNotepad++

Regex Problem Overview


I am trying to find and delete a line using Notepad++

I need to find lines in this file (UNIX Format) that match the string '#RedirectMatch Permanent' and delete that line.

Does anyone know how to do this using Notepad++ Find and Replace?

Thanks and Kind Regards,

Regex Solutions


Solution 1 - Regex

Step 1

  • SearchFind → (goto Tab) Mark
  • Find what: ^Session.*$
  • Enable the checkbox Bookmark line
  • Enable the checkbox Regular expression (under Search Mode)
  • Click Mark All (this will find the regex and highlights all the lines and bookmark them)

Step 2

  • SearchBookmarkRemove Bookmarked Lines

Solution 2 - Regex

If it supports standard regex...

find:
^.*#RedirectMatch Permanent.*$

replace:

Replace with nothing.

Solution 3 - Regex

Provide the following in the search dialog:

Find What: ^$\r\n
Replace With: (Leave it empty)

Click Replace All

Solution 4 - Regex

Combining the best from all the answers

enter image description here

Solution 5 - Regex

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?
  • If your file have windows (CRLF) line ending : $(\r\n)?

For instance, in your case :

.*#RedirectMatch Permanent.*$\n?

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiontestView Question on Stackoverflow
Solution 1 - RegexParasouView Answer on Stackoverflow
Solution 2 - RegexStefan KendallView Answer on Stackoverflow
Solution 3 - RegexSuresh AnbarasanView Answer on Stackoverflow
Solution 4 - RegexGauthaman SahadevanView Answer on Stackoverflow
Solution 5 - RegexmagnetikView Answer on Stackoverflow