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?
You can use this regular expression:
(\r?\n){4,}
And replace it with this
\n
\r?\n
).\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>