BBEdit-compatible regex for remove blank lines

15.7k Views Asked by At

i've tried other regexes that are supposed to be able to remove blank lines from a document, but none of them seem to work within BBEdit's find-and-replace.

What is a regex for stripping blank lines from a document that will work in bbedit?

7

There are 7 best solutions below

0
steveax On

I'm going to assume that there may be whitespace in the lines you wish to remove. This should do the trick:

^\s*?\r

(replace with nothing, make sure the "Grep" checkbox is ticked)

4
Vortexfive On

I find it easier to choose "Text>Process lines containing..." with the expression:

^$

or

^\s*$

Check the "Use grep" and "Delete matched lines" box. Uncheck all others.

0
Adam On

This works in Coda. (Not sure about BBEdit though)

Find:

\n\n

Replace with:

\n 

Make sure the "Use Regular Expressions" option is checked.

0
Luc-Olivier On

To remove all blank lines whatever the amount of blank lines between not blank lines, whatever the amount been regular or not.

You must proceed that way:

1st you remove all the blank lines with

 « Text Menu / Process Lines Containing... »
 > Regex : ^$
 > Use grep enabled
 > Delete matched line enabled

2d if you want to recover legibility add a blank line after your blocks for instance

 « Search Menu / Find... »
 > Grep enabled
 > Find: ^}$        <<<< because the final curly is usually the 1st and the last char
 > Replace: }\n     <<<< or \r or \r\c according to the Platform choice
0
Ronnie On

Find: \r+ Replace with: \r

Grep option should be checked.

0
Rama Suresh A On

BBEdit.. Text --> process duplicate lines. Delete duplicate lines

0
Michael Tweed On

For truly blank lines in BBedit, I search for:

^$\r

and replace with nothing. This finds the blank lines and removes the contents of the line and the linefeed.

An alternative I have used when I forget how to match a linefeed is to use:

.+ 

…to match one or more characters and then use the extract button rather than replace all. Instead of deleting your blank lines, you are keeping any line with something on it.