I would like to remove excessive empty lines from a string, but allow one empty line between every line. Like:
line1
line2
Should become:
line1
line2
I did find the following regex (forgot where i found it):
preg_replace('/^\n+|^[\t\s]*\n+/m','',$message);
This works, but removes all empty lines without leaving an empty line between every line.
Edit: I just created a quick example at http://jsfiddle.net/RAqSS/
Try replacing:
with:
Like this:
If you don’t want an empty line, you would change the
{2,}to a+and use a single\n. It would actually work with a+instead of{2,}. The{2,}is an optimization.