Re: regex \s == \n???



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)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


.



Relevant Pages

  • RE: How to extract variable and its value from URL
    ... > and I need a regex or some solution to extract 'a' variable and its ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: RegularExpressions
    ... is it possible to create regular expression, ... I know I can use "joe+" regex, but this returns true in case the ... string "joe" is present but I need to get false in that case. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: RegularExpressions
    ... I have to check when the password doesn't contain username nor reverse ... I know I can use "joe+" regex, but this returns true in case the ... string "joe" is present but I need to get false in that case. ...
    (microsoft.public.dotnet.languages.csharp)
  • RegularExpressions
    ... I have to check when the password doesn't contain username nor reverse ... I know I can use "joe+" regex, but this returns true in case the string ...
    (microsoft.public.dotnet.languages.csharp)

Loading