Notepad++ Delete Lines with Find & Replace
Solution 1
Use the "Extended" setting in the Replace window (not "Regular expression": I'm sure there's a way to do it with Regular expression, but using "Extended" works fine).
Enter ".pPrev.\r\n
" in the "Find what" field, and leave the "Replace what" field blank. This will include the \r\n characters in the match and delete the whole line.
Solution 2
Using the "Regular expression search" option in the Find & Replace window:
Define the regex Find string that you are looking for, and include the \xd?\xa
"end-of-line" characters in the match.
If want to delete these line brakes then leave the Replace string blank.
Note, the carriage return character is optional (\xd?
), because you could have lines ending with no carriage return and only a line feed character \xa
.
Solution 3
You can actually select the newline by moving your cursor from the end of one line to the beginning of the next:
first line(from here)
(to here)decond line
third line
Then press ctrl+h while the new line is selected, and replace with nothing. This will delete all the newlines.
Solution 4
The general principle whichever editor you're using is that you need to include the new line characters (\r\n
assuming Windows line endings) in your search so that they will be included in the replacement and thus removed.
In Notepad++ this is made a bit more confusing by the 2 different search and replace commands. See this Wiki page for details: Replacing Newlines in Notepad++
I only had an old version of Notepad++ to hand so had to use Extended Search (accessed via ^R), making sure Regular Expr was unticked and using ^M to insert the new line character into the Find field. However if you make sure you're using Notepad++ 4.9 or later you should be able to use \r
and \n
in the regexp mode.
Related videos on Youtube
Jim Fell
Technical expertise resides in developing firmware and PC-interface software for embedded systems using C/C++/C# programming languages, integrated development environments, and low-level debugging techniques. I enjoy developing embedded and PC drivers for wired communications. Previous work focused on the development of firmware for USB, CAN, SPI, RS-232, RS-485, ZigBee, and analog drivers, as well as implementing low-power embedded solutions across a broad range of embedded and desktop platforms.
Updated on September 17, 2022Comments
-
Jim Fell almost 2 years
Does anyone know how to delete a line using Find & Replace in Notepad++ ?
In my Find query it finds the proper lines okay: ^.pPrev.$ In the Replace field, I leave it blank thinking the line should deleted (i.e. replaced with nothing), but the newline and endline characters remain.
-
Justin over 13 yearsI'm not able to use
\r
or\n
in RegEx mode (version 5.8.6). They only work in Extended mode for me. -
dtech almost 13 yearsDoes not work anymore in later Notepad++ versions (5.9.2 UNICODE tested)
-
Jim Fell over 12 yearsIt seems like they keep pulling good features from Notepad++. First, the FunctionList plugin and now this. :(
-
user4951 over 11 yearsstill working. If not, delete \n first and then delete \r
-
mabho about 11 yearsI came here looking for info on how to remove line breaks and \r\n worked for me like a charm. Thanks!
-
id.ot over 6 yearsThis worked for me where all other answers (pertaining to Notepad++) did not. I'm using v7.5.1