11.35. Replace spaces

s/^\s*//        leading
s/\s*$//        tailing

Better to write:
s/^\s+//        leading
s/\s+$//        tailing

both ends:

s/^\s*(.*)\s*$/$1/   " abc " =>  "abc "  because of the greediness
s/^\s*(.*?)\s*$/$1/   " abc " =>  "abc"  minimal match

If you are interested in on-site trainings by the author, please contact me directly.

Online courses:

Would you like to get
updated when I publish
the next article?

Follow me:

Google Plus Twitter RSS feed