in reply to Regex Question

A little bit of lookahead/lookbehind should do it:
s/(?<!\n)\n(?!\n)//g;
If that seems overly complex, then look for runs of newlines, and don't touch the ones that aren't isolated:
s/(\n+)/$1 eq "\n" ? "" : $1/eg;

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re: Re: Regex Question
by salvadors (Pilgrim) on Jan 08, 2001 at 00:18 UTC

    A bit of benchmarking shows that the first is about twice as fast as the second, and about three times faster than my verison...

    I really must get around to reading the regex book... it's been sitting on my desk for months now.

    Tony