0

I was trying to clean my repo from multiple empty lines in code (more than 4) with bfg repo cleaner. I tried various regular expressions, but didn't come up with a solution. The closest result I achieved was simply removing all new lines from a file.

Any ideas how I can do this with bfg or any other tool?

Vadym Sidorov
  • 85
  • 1
  • 8

1 Answers1

1

You can use this regular expression:

(\r?\n){4,}

And replace it with this

\n
  • It will accept the UNIX and the Windows linebreak (\r?\n).
  • It matches if at least 4 line endings are consecutive (without spaces on each of the lines)
  • All the consecutive linebreak characters are replaced by a single UNIX linebreak (\n)

Here is an executable example:

var text = document.getElementById("main").innerHTML; // read HTML because it is easier to write linebreaks in HTML
var regex = /(\r?\n){4,}/g;
var replacement = "\n";

var result = text.replace(regex, replacement);
console.log(text);
console.log(result);
<div id="main">








line1




line2


line3





</div>
ssc-hrep3
  • 15,024
  • 7
  • 48
  • 87
  • Thanks for the answer! In bfg replacements.txt file it would look like: regex:(\r?\n){4,}==>\n in case someone wondered. – Vadym Sidorov Jan 23 '17 at 17:20