in reply to regex to replace linefeeds with <p> tags
One simple method of fixing it immediately comes to mind.
Since it's HTML, why not just skip putting the newline before and after the </p> ... <p>:
$in{$_} =~ s/([\r\n]){2,}/<\/p><p>/g;
That way, you at least avoid the newline accumulation problem.
Update: If you really have your heart set on putting them on the same line, something like:
$in{$_} =~ s/(?!^<\/p><p>)([\r\n]){2,}/\n<\/p><p>\n/g;
Might do the trick. It uses a zero-width negative lookbehind assertion, which avoids adding </p> ... <p> to any line which contains that pair (and only that pair) already.
|
|---|