in reply to Removing empty line(s) with regex in a multiple strings in a variable
(I could also point out that in your regex, the square brackets and "m" and "x" modifiers could all be removed and it would do the same thing it does now -- including them has no effect at all in this case. Of course, this also means they do no harm, but if you don't understand why they do nothing in this case, it wouldn't hurt you to try reading the perlre manual page.)
As GrandFather points out, you only want to eliminate the extra "\n" characters. The specific output that you say you want (with the initial "\n" still intact) would come out with just this:
(updated to emulate GrandFather's handling of "blank" lines that contain just spaces and/or tabs)s/\n\s*/\n/g; # every string of \n plus 0-or-more whitespace --> sing +le \n
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Removing empty line(s) with regex in a multiple strings in a variable
by Strazhnik (Initiate) on Apr 27, 2010 at 15:14 UTC |