From: Warren Brown Date: 2003-06-28T01:31:57+09:00 Subject: Re: \s in regex s, > 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. That is correct. /\s/ is the same as /[\s\t\r\n\f]/ or, in English, spaces, TABs, Carriage Returns (CR), Line Feeds (LF), and Form Feeds (FF). If *all* you want to remove is spaces, use / /: ifile.each { | line | ofile.print line.sub(/^ +/,"").sub(/ +$/,"") } I hope this helps. - Warren Brown