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"