I have some text like
This is a line
This is other line
This is another line
How to get rid of those multi empty lines ?
What I want is
This is a line
This is other line
This is another line
\s says that matches any whitespace character (spaces, tabs, line breaks) but I cannot figure out how to make multi empty line to just one empty line ?
\rbeing optional lets it work with Unix-style line terminators. The output will have Windows-style terminators, though.\s*allows it to match on lines that contain whitespace. (I had originally put in a?here to make the match non-greedy, but that’s not actually necessary and possibly detrimental in this case. In .NET regular expressions,\sand.don’t match newlines with the defaultRegexOptions.){2,}makes sure it will only match with two successive newlines separated only by whitespace.