Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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
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 imbibing at the Monastery: (13)
As of 2015-07-28 15:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (257 votes), past polls