jackassplus wrote:
> I am trying to remove single newlines but not double newlines.
>
> for instance say I have the following:
> Name:\nMy Name\n\nAddress:\n123 Anywhere St\n\nAbout Me:\nSome text
> that\nhas some newlines that\nI want to be rid of\n\nThe End\n
>
> I want to get rid of all of the newlines between Me:\n and the next
> occurrence of \n\n. and replace them with spaces so it says:
> Name:\nMy Name\n\nAddress:\n123 Anywhere St\n\nAbout Me:\nSome text
> that has some newlines that I want to be rid of\n\nThe End\n
>
> I'm completely at a loss on how to pull this off...
>
> sub fixer($){
> my $data = $_[0];
> $data =~ s/\\n{1}/ /g; #this is too greedy
> print $data;
> }
>
>
Try:
my $data = "\nMy Name\n\nAddress:\n123 Anywhere St\n\nAbout Me:\nSome
text that\nhas some newlines that\nI want to be rid of\n\nThe End\n";
print "<<$data>>\n";
$data =~ s{ (?<! \n ) \n (?! \n ) }{}gmsx;
print "<<$data>>\n";
--
Just my 0.00000002 million dollars worth,
Shawn
Programming is as much about organization and communication
as it is about coding.
I like Perl; it's the only language where you can bless your
thingy.
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/