Remove empty lines in text using Visual Studio

Alaa picture Alaa · Sep 17, 2012 · Viewed 93.9k times · Source

How to remove empty lines in Visual Studio?

Answer

Lennart picture Lennart · Dec 21, 2012

Since Visual Studio 2012 changed its regex syntax, the original answers by Ala translate into the following in VS 2012:

Remove single blank lines

Old:

^:b*$\n

New:

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

Visual Studio 2013 (thanks to BozoJoe and Joe Johnston):

^\s*$\n

Remove double blank lines

Old:

^:b*\n:b*\n

New:

^(?([^\r\n])\s)*\r?\n(?([^\r\n])\s)*\r?\n

Rolls right off your tongue.

Here is the conversion sheet from MSDN.