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

Re^2: Pulling white space off before/after string?

by ecuguru (Monk)
on Apr 17, 2007 at 04:58 UTC ( [id://610459]=note: print w/replies, xml ) Need Help??


in reply to Re: Pulling white space off before/after string?
in thread Pulling white space off before/after string?

I just came back to post I found a working solution:
$buff =~ s/ *$//; #Remove Trailing Spaces $buff =~ s/^ *//; #Remove Leading Spaces
You've got the same idea I have, but I'm too regex newbie to figure out the differences. Can you tell me if there are any differences in our regexes?
Thanks!!

Replies are listed 'Best First'.
Re^3: Pulling white space off before/after string?
by bobf (Monsignor) on Apr 17, 2007 at 05:09 UTC

    / *$/ means 'match zero or more space characters anchored to the end of the string', which will always match since it can always match zero characters. It will also match only space characters - other white space (such as tabs) will not match.

    /\s+$/ means 'match one or more white space characters anchored to the end of the string'. The \s includes spaces, tabs, and other forms of white space.

    See perlre for more information. The Tutorials section also has several entries in Pattern Matching, Regular Expressions, and Parsing, which you may find helpful.

Re^3: Pulling white space off before/after string?
by GrandFather (Saint) on Apr 17, 2007 at 05:06 UTC

    You are matching only space characters. bobf's version matches any white space characters (which includes spaces, tabs and various other characters including UNICODE white space characters).


    DWIM is Perl's answer to Gödel

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-04-26 08:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found