From: Michael Campbell Date: 2003-06-27T22:48:52+09:00 Subject: Re: \s in regex Not the answer to your question necessarily, but try String#strip (or its bang cousin) -----Original Message----- From: s moon [mailto:internetletter@yahoo.com] Sent: Friday, June 27, 2003 8:47 AM To: ruby-talk ML Subject: \s in regex what I want is to remove beginning and trailing spaces from lines. this is a failed try. ifile.each { | line | ofile.print line.sub(/^\s+/,"").sub(/\s+$/,"") } this removes spaces from begin and end of lines but it also removes blank lines. it seems \s matches \r or \n also. this is another one, this time it works. ifile.each { | line | if line =~ /^\s*$/ # take care of blank lines ofile.print line else ofile.print line.sub(/^\s+/,"").sub(/\s+$/,"") end } but can i do this with one line without if-then-else? thanks