Tom Cloyd
2/6/2009 12:28:00 PM
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!
t.
joe chesak wrote:
> Tom,
>
> If you're just speaking of the space character and you want to replace
> double-spaces (or triple-spaces or more) with just a single space, you can
> do this.
>
> puts a.gsub(/ +/," ")
>
> Joe
>
> On Fri, Feb 6, 2009 at 1:10 PM, Tom Cloyd <tomcloyd@comcast.net> 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.
>>
>> Can someone more knowledgeable tell me is there's a way to do this - remove
>> extra spaces without removing the EOLs?
>>
>> Thanks!
>>
>> t.
>>
>> --
>>
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
>> Bellingham, Washington, U.S.A: (360) 920-1226
>> << tc@tomcloyd.com >> (email)
>> << TomCloyd.com >> (website) << sleightmind.wordpress.com >> (mental
>> health weblog)
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>
>>
>>
>>
>
>
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~