Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: trim leading & trailing whitespace

by BrowserUk (Pope)
on Mar 30, 2005 at 08:06 UTC ( #443368=note: print w/ replies, xml ) Need Help??


in reply to trim leading & trailing whitespace

s[^\s*(.*)\b\s*$][$1]

Update: Corion rightly points out that this does not work correctly for lines where the last non whitespace character is a non-words character. Eg.

the quick brown fox ( \n # ^

So, use s[^\s*(.*\S)\s*$][]; instead. It's slower, but still quicker than the FAQ method.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco.
Rule 1 has a caveat! -- Who broke the cabal?


Comment on Re: trim leading & trailing whitespace
Select or Download Code
Re^2: trim leading & trailing whitespace
by ady (Deacon) on Mar 30, 2005 at 08:46 UTC
    Good one too (needs the gm modifiers to do the job tho') -- allan

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2014-09-21 15:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (172 votes), past polls