From: Joel VanderWerf Date: 2011-04-27T01:31:32+09:00 Subject: Re: Replace any multiple whitespaces with single white space On 04/26/2011 05:03 AM, Brian Candler wrote: > Joel VanderWerf wrote in post #994935: >> On 04/25/2011 11:44 AM, Michelle Pace wrote: >>> pattern incorrect? >>> >>> descrip = "1/4 WELDING LEVER FRONT DRW 14844-C MAT WMA1CM-WLFRONT" >>> descrip.sub!(/\s+/,' ') >>> puts descrip >> >> sub! only affects the *first* match. You can substitute globally with >> gsub. Also you might as well only match 2 or more spaces: >> >> descrip.gsub!(/\s\s+/,' ') > > Those are not equivalent, because \s matches more than just ASCII 0x20. > > d1 = "foo\tbar\tbaz" > d1.gsub(/\s+/,' ') # "foo bar baz" > d1.gsub(/\s\s+/,' ') # "foo\tbar\tbaz" You're right. What I said in another post about preserving tabs isn't what the original sub! call was doing anyway. (sorry for the empty reply previously)