Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: remove single blank lines?

by Roger (Parson)
on Dec 09, 2003 at 00:24 UTC ( [id://313316]=note: print w/replies, xml ) Need Help??


in reply to remove single blank lines?

Here's my implementation -
$text =~ s/(?<=\b)\n(?=\n\b)//g;
Consider the string below -
This is line1\n \n line3\n \n \n
What the regex will do is to get rid of the '\n' at the end of line1, which is followed by another \n and a word boundary.

This solution is similar to qq's answer above, but with subtle differences. qq's solution will replace two consecutive \n's with a single \n, while my solution will get rid of the first \n.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://313316]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-23 22:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found