Re: regex \s == \n???
- From: Tom Cloyd <tomcloyd@xxxxxxxxxxx>
- Date: Fri, 6 Feb 2009 07:28:26 -0500
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@xxxxxxxxxxx> 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@xxxxxxxxxxxx >> (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@xxxxxxxxxxxx >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.
- Follow-Ups:
- Re: regex \s == \n???
- From: David A. Black
- Re: regex \s == \n???
- References:
- regex \s == \n???
- From: Tom Cloyd
- Re: regex \s == \n???
- From: joe chesak
- regex \s == \n???
- Prev by Date: Re: regex \s == \n???
- Next by Date: Re: regex \s == \n???
- Previous by thread: Re: regex \s == \n???
- Next by thread: Re: regex \s == \n???
- Index(es):
Relevant Pages
|
Loading