ndequeker
ndequeker

Reputation: 8010

SublimeText remove empty lines

I have an HTML-file that lists all FontAwesome icons. Between the markup for each icon, there is a new line indented with spaces.

HTML

              <div class="fa-hover col-md-3 col-sm-4"><i class="fa fa-cloud-upload"></i> fa-cloud-upload</div>
            
              <div class="fa-hover col-md-3 col-sm-4"><i class="fa fa-code"></i> fa-code</div>
            
              <div class="fa-hover col-md-3 col-sm-4"><i class="fa fa-code-fork"></i> fa-code-fork</div>
            
              <div class="fa-hover col-md-3 col-sm-4"><i class="fa fa-coffee"></i> fa-coffee</div>
            
              <div class="fa-hover col-md-3 col-sm-4"><i class="fa fa-cog"></i> fa-cog</div>

Question

Which regex can I use to easily select these lines between the markup of all icons? It should only remove the empty lines and keep the indenting of lines containing markup. I want to execute a find-and-replace with this regex in SublimeText.

Desired output

              <div class="fa-hover col-md-3 col-sm-4"><i class="fa fa-cloud-upload"></i> fa-cloud-upload</div>
              <div class="fa-hover col-md-3 col-sm-4"><i class="fa fa-code"></i> fa-code</div>
              <div class="fa-hover col-md-3 col-sm-4"><i class="fa fa-code-fork"></i> fa-code-fork</div>
              <div class="fa-hover col-md-3 col-sm-4"><i class="fa fa-coffee"></i> fa-coffee</div>
              <div class="fa-hover col-md-3 col-sm-4"><i class="fa fa-cog"></i> fa-cog</div>

Upvotes: 0

Views: 2274

Answers (3)

Jerry
Jerry

Reputation: 71598

Try the regex:

^\s*$[\r\n]+

And replace with nothing.

^ matches the beginning of the line, \s* matches any potential space, tabs and such, $ will match the end of the line.

The next [\r\n]+ is to bring back the next line into the current line and will match newlines and carriage returns.

Upvotes: 1

zessx
zessx

Reputation: 68818

Search for this pattern, and replace it by nothing.

\n\s*$

Remember to enable the regex mode in your search & replace.

Upvotes: 3

Some programmer dude
Some programmer dude

Reputation: 409482

If the lines are truly empty, and doesn't contain any spaces or tabs, then ^$ should be enough. The ^ character matches the beginning of a line, and $ matches the end of a line.

Upvotes: 0

Related Questions