From: mike@... (Mike Stok) Date: 2003-06-27T23:27:26+09:00 Subject: Re: \s in regex In article , s moon wrote: >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. One approach might be to use String#strip as suggested by another poster, and to use IO#puts to supply the line ending e.g. ifile.each { |line| ofile.puts line.strip } This is "quick and dirty" and will add a \n to the last line from the input even if there wasn't a final \n in the inpyt stream. Hope this helps, Mike -- mike@stok.co.uk | The "`Stok' disclaimers" apply. http://www.stok.co.uk/~mike/ | GPG PGP Key 1024D/059913DA mike@exegenix.com | Fingerprint 0570 71CD 6790 7C28 3D60 http://www.exegenix.com/ | 75D2 9EC4 C1C0 0599 13DA