13

I'm using Notepad++ and basically I want to find all blank lines that don't contain text using Notepad++ regex. I know that there is a simpler way of doing this by using 'textfx,' but I'm looking for an expression to do this. Here is an example below with the symbols shown.

< ?php **CRLF**
**CRLF**                        *<- REMOVE THIS* 
$xxx = $_POST['xxx'];**CRLF**
$xxx = $_POST['xxx'];**CRLF**
$xxx = $_POST['xxx'];**CRLF**
**CRLF**                        *<- REMOVE THIS* 
**CRLF**                        *<- REMOVE THIS* 
if ($xxx)**CRLF**
{**CRLF**
Justin
  • 6,611
  • 3
  • 36
  • 57
keith Fesed
  • 131
  • 1
  • 1
  • 3

6 Answers6

25

Not a regular expression, but Notepad++ 6.3.2 has a number of ways of removing blank lines without using a regular expression.

Menu => Edit => Line operations => Remove empty lines

Menu => Edit => Line operations => Remove empty lines (containing blank characters)

Menu => TextFx => TextFx Edit => Delete blank lines

Menu => TextFx => TextFx Edit => Delete surplus blank lines

The two TextFx methods only delete empty lines, but they can be preceded with either of:

Menu => Edit => Blank operations => Trim trailing spaces

Menu => TextFx => vTextFx Edit** => Trim trailing spaces

AdrianHHH
  • 13,492
  • 16
  • 50
  • 87
9

I just did find ^\r\n and replace with nothing

Ivan
  • 91
  • 1
  • 1
9

I've only been able to do this by using the "Extended" search mode in the Replace dialog (not "Regular expression" mode).

The search term I use is \r\n\r\n, and I replace it with \r\n. You have to keep repeating this until there were no changes, if there can be even more newlines in a row.

I also wish there was a better RegEx engine in Notepad++ with the ability to do multi-line searches.

Justin
  • 6,611
  • 3
  • 36
  • 57
  • Ok thanks for the quick reply. but when i use \r\n and replace with nothing all the code moves to one line anyway to solve this? – keith Fesed Mar 21 '11 at 17:50
  • @keith - Sorry, I already edited my post -- you need to search for two sequential newline sequences and replace them with a single one. – Justin Mar 21 '11 at 17:52
  • This is good if you have done "trim trailing and save" first. Otherwise whitespace will spoil it. – mckenzm Oct 10 '17 at 01:00
4

Its possible, but not directly.

In short, go to the search, use the regex ^$ to search, check "mark lines" (in the current version there is a seperate mark tab in the search dialogue) and click "Find all". It results in bookmarks for all those lines.

In the search menu there is a point "delete bookmarked lines" thats it.

stema
  • 90,351
  • 20
  • 107
  • 135
0

In Notepad v6.2.2 there is option called Extended(\t\n......)
and In replace box, provide \r\n it works fine

MyStack
  • 103
  • 2
  • 12
0

Without using TextFx I don't think you can. There's no way I know of to tell the Find and Replace in Notepad++ that you want to delete the line. You can find all those lines by searching for '^$' (minus the quotes) with Regular Expression turned on. But the best you can do is replace it with an empty string, not a delete.

AlG
  • 14,697
  • 4
  • 41
  • 54