J
Jason
I've gone through about a dozen options, and none of them work
correctly! This is driving me nuts.
The request is pretty simple: I have a form with a textarea field, and
I want to remove any opening or trailing carriage returns from it
(while leaving any return in the middle). This is the code I tried most
recently, and was certain would work:
$comment =~ s/^\r\n+|^\r+|^\n+|\r\n+$|\r+$|\n+$//g;
But, it doesn't seem to have any impact at all! Correct me if I'm
wrong, but I thought that this broke down like:
s/ # substitute
^\r\n+| # start at the beginning, find all \r\n until you find
something else, OR
^\r+| # same as above, finding only \r, OR
^\n+| # same, finding only \n, OR
\r\n+$| # finding all \r\n that go to the end uninterrupted, OR
\r+$| # same, finding only \r, OR
\n+$ # same, finding only \n
// # replace any of the above with nothing
g; # do this globally
I also tried breaking it down into 2 separate recipes, which had no
impact:
$comment =~ s/^\r\n+|^\r+|^\n+//g;
$comment =~ s/\r\n+$|\r+$|\n+$//g;
Not surprisingly, this one DOES work to remove whitespaces (taken from
the FAQ):
$comment =~ s/^\s+|\s+$//g;
This should be the same thing as my recipe above, but instead of \s,
I've used \r, \n, or some variation.
Do you guys see what I'm overlooking?
TIA,
Jason
correctly! This is driving me nuts.
The request is pretty simple: I have a form with a textarea field, and
I want to remove any opening or trailing carriage returns from it
(while leaving any return in the middle). This is the code I tried most
recently, and was certain would work:
$comment =~ s/^\r\n+|^\r+|^\n+|\r\n+$|\r+$|\n+$//g;
But, it doesn't seem to have any impact at all! Correct me if I'm
wrong, but I thought that this broke down like:
s/ # substitute
^\r\n+| # start at the beginning, find all \r\n until you find
something else, OR
^\r+| # same as above, finding only \r, OR
^\n+| # same, finding only \n, OR
\r\n+$| # finding all \r\n that go to the end uninterrupted, OR
\r+$| # same, finding only \r, OR
\n+$ # same, finding only \n
// # replace any of the above with nothing
g; # do this globally
I also tried breaking it down into 2 separate recipes, which had no
impact:
$comment =~ s/^\r\n+|^\r+|^\n+//g;
$comment =~ s/\r\n+$|\r+$|\n+$//g;
Not surprisingly, this one DOES work to remove whitespaces (taken from
the FAQ):
$comment =~ s/^\s+|\s+$//g;
This should be the same thing as my recipe above, but instead of \s,
I've used \r, \n, or some variation.
Do you guys see what I'm overlooking?
TIA,
Jason