5

Sometimes, copy pasting code from my email makes everything have an extra blank line.

For example

1: hi
2:
3: hello
4:

Is there a way to target these empty lines with regex and delete them? I'm using notepad++ with the search(with regex) and replace capability.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
dukevin
  • 22,384
  • 36
  • 82
  • 111

4 Answers4

9

Because Notepad++ regex operates only line by line, without a multi-line mode, you can't remove entire lines with regex alone. This is no longer true as of Notepad++ 6.0, which now uses PCRE as its regex engine and allows for multi-line replacements. See this answer for more info.

The TextFX plugin that Notepad++ ships with allows you to remove blank lines without using regex. Just highlight your entire document (Ctrl+A) and do TextFX > TextFX Edit > Delete Blank Lines. If your selection or document begins and/or ends with a blank line though, those lines won't be removed automatically — but removing those is just a matter of:

  1. Ctrl+Home

  2. Del

  3. Ctrl+End

  4. Backspace

Community
  • 1
  • 1
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
1

To remove double spacing in Notepad++ (I'm using v7.8.4) go to: Edit, Line Operations, Remove Empty Lines.

geca
  • 2,711
  • 2
  • 17
  • 26
0
  • Search > Replace...

Search Mode = Extended

Find what : \r\n\r\n

Replace with : \r\n

HackSlash
  • 4,944
  • 2
  • 18
  • 44
0

I don't have notepad++, but the regular expression "^$" (without the quotes) matches only blank lines. Perhaps notepad++ will allow you to replace matches of that regular expression with the empty string, thus removing the blank lines.

Croad Langshan
  • 2,646
  • 3
  • 24
  • 37