From: Mark Thomas Date: 2009-02-06T21:44:27+09:00 Subject: Re: regex \s == \n??? On Feb 6, 7:10 am, Tom Cloyd wrote: > I'm trying to remove extra spaces from a long string which has some > EOLs, using regex. It's not working. Here's a simple demo: > > irb(main):004:0> a="\n  abc\n  a  a  a" > => "\n  abc\n  a  a  a" > irb(main):005:0> a.gsub(/\s+/,' ') > => " abc a a a" > > I've dug around in my regex references, and all I can say is that is > hasn't been the least bit helpful. I'm probably not looking for the > right thing. A newline is a whitespace char. \s is the same as [ \t\r\n\f]. If you don't want to match them, remove them. Try a.gsub(/[ \t]+/,' ') --Mark