Hi --

On Fri, 6 Feb 2009, Tom Cloyd wrote:

> Stefano, Joe - thank you! I'm only just getting into regex, so I get easily 
> lost. You solved my problem - each in different ways. A lot of bang for the 
> buck, indeed!

Another variant:

   a.gsub(/[^\S\n]+/, " ")

That character class means "all characters that are not a non-space or
\n." (The ^ is the "not" part.)

You might also be able to use squeeze:

   p "abc    def   \n   ghi\n".squeeze   # "abc def \n ghi\n"

though that's going to be less versatile if you're dealing, say, with
tabs.


David

-- 
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)

http://www.wishsight.com => Independent, social wishlist management!