I've got text some text with line breaks. I want to strip all line breaks, unless there are two next to each other.

Here is what I have:

Code: $text = "This is not good,\n you know what I mean?\n\nThis should be o +n a separate line."; $text =~ s/[^\n]\n[^\n]//g; print $text; Run: C:\Perl>perl test.pl This is not goodyou know what I mean? This should be on a separate line. Should Print: This is not good, you know what I mean? This should be on a separate line.
The (^\n) 's (brackets linked it, so I used parentheses there) are being substituted out, too, which is not wanted. How would I get around this?

Thanks,
madhatter


In reply to Regex Question by madhatter

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.