SitePoint Enthusiast
Hello everyone,
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]
123";
$var2 = "123
[leave intact";
$var =~ s/(\] |\]\n)+/\]/g;
$var2 =~ s/( \[|\n\[)+/\[/g;
print "\$var = $var \n\n";
print "\$var2 = $var2 \n\n";
[/code]
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.
Be Well
SitePoint Enthusiast
I already fixed it, thanks anyway.
I changed the code above to:
$var =~ s/\]\s+/\]/g;
and
$var2 =~ s/\s+\[/\[/g;
and it works as intended, I used \s to account for all white space.
Be Well
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks