in reply to regex to replace linefeeds with <p> tags

Hi jck,

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.


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/