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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: trim leading & trailing whitespace
by ady (Deacon) on Mar 30, 2005 at 08:46 UTC |