Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
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?

Replies are listed 'Best First'.
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 chanting in the Monastery: (1)
As of 2016-07-31 02:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What is your favorite alternate name for a (specific) keyboard key?


















    Results (269 votes). Check out past polls.