I'm trying to remove leading and trailing spaces and blank lines from a string but is not working, is only doing it for the first match. Could someone be so kind as to give me any insight on this code?
<BLOCKQUOTE><font size="1" face="Verdana, Arial">code /font><HR><pre>
$var = "leave intact]
$var2 = "123
$var =~ s/(\] |\]\n)+/\]/g;
$var2 =~ s/( \[|\n\[)+/\[/g;
print "\$var = $var \n\n";
print "\$var2 = $var2 \n\n";
I would like to remove every space and blank line after "]" and before "[" so that I get "leave intact]123" and "123[leave intact" as a result.
Any comments and suggestions would be greatly appreciated.
Thanks in advance for your cooperation.
I already fixed it, thanks anyway.
I changed the code above to:
$var =~ s/\]\s+/\]/g;
$var2 =~ s/\s+\[/\[/g;
and it works as intended, I used \s to account for all white space.