Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regex in Notepad++ to remove blank lines

I have multiple html files and some of them have some blank lines, I need a regex to remove all blank lines and leave only one blank line.. So it removes anything more than one blank line, and leave those that are just one or none (none like in having text in them).

I need it also to consider lines that are not totally blank, as some lines could have spaces or tabs (characters that doesn't show), so I need it to consider these lines with the regex to be removed as long as it is more than one line..

like image 621
Mike Avatar asked Nov 29 '22 02:11

Mike


2 Answers

Search for

^([ \t]*)\r?\n\s+$

and replace with

\1

Explanation:

^         # Start of line
([ \t]*)  # Match any number of spaces or tabs, capture them in group 1
\r?\n     # Match one linebreak
\s+       # Match any following whitespace
$         # until the last possible end of line.

\1 will then contain the first line of whitespace characters, so when you use that as the replacement string, only the first line of whitespace will be preserved (excluding the linebreak at the end).

like image 174
Tim Pietzcker Avatar answered Dec 04 '22 02:12

Tim Pietzcker


This worked for me on notepad++ v6.5.1. UNICODE windows 7

Search for: ^[ \t]*\r\n

Replace with: nothing, leave blank

Search mode: Regular expression.

like image 44
Ivan Avatar answered Dec 04 '22 03:12

Ivan