BBEdit-compatible regex for remove blank lines
Asked Answered
P

7

9

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?

Positron answered 9/8, 2012 at 21:4 Comment(0)
L
16

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)

Lyford answered 9/8, 2012 at 21:26 Comment(0)
F
6

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.

Fotina answered 14/8, 2012 at 7:23 Comment(4)
There is no 'Delete matched lines' option in BBEdit 12.Figge
@Figge first select "Text>Process lines containing...", in the dialog box that appears there is a checkbox "Delete matched lines" (at least in my version of BBEdit 12)Fotina
Your method only works on lines containing at least one space symbol. If the line contains nothing, your method won't work.Figge
@Figge I'm getting the same result (erases only lines with one or more space), but that doesn't make sense, as * should match zero or one. What's up there? Looks like the $ requires a second line -- when I did a search & replace with the same regex (^\s*$), it removed all but the last line in each batch of empty lines.Nomothetic
C
2

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

Find:

\n\n

Replace with:

\n 

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

Citric answered 15/10, 2013 at 0:35 Comment(0)
E
2

Find: \r+ Replace with: \r

Grep option should be checked.

Ergot answered 31/10, 2017 at 22:7 Comment(0)
R
1

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

Redblooded answered 13/10, 2020 at 5:45 Comment(0)
M
0

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
Metzger answered 18/6, 2016 at 14:11 Comment(0)
C
0

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.

Checkrein answered 25/8, 2022 at 18:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.