gsub and regex

T

Tom Cloyd

I'm trying to replace all /\n / with /\n/ in a string, but gsub won't
allow a regex as the replacement when a match occurs. I'm getting myself
considerably confused about data types and regex, and just plain need
some help. Is there some way to do this replacement, using gsub?

Thanks,

t.

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC
Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< (e-mail address removed) >> (email)
<< TomCloyd.com >> (website & psychotherapy weblog)
<< sleightmind.wordpress.com >> (mental health issues weblog)
<< directpathdesign.com >> (web site design & consultation)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
S

Stefano Crocco

I'm trying to replace all /\n / with /\n/ in a string, but gsub won't
allow a regex as the replacement when a match occurs. I'm getting myself
considerably confused about data types and regex, and just plain need
some help. Is there some way to do this replacement, using gsub?

Thanks,

t.

I'm not sure I understand you. Do you want to replace all newline charactes
followed by a space with a single newline character? If so, you don't need
regexps at all:

str.gsub("\n ", "\n")

I hope this helps

Stefano
 
T

Tom Cloyd

Stefano said:
I'm not sure I understand you. Do you want to replace all newline charactes
followed by a space with a single newline character? If so, you don't need
regexps at all:

str.gsub("\n ", "\n")

I hope this helps

Stefano
Man, this list is absolutely amazing. Here I am programming at 4:30 in
the morning, and get stuck, and before I can execute my program again, I
get my problem solved. I think I want to live in Ruby land the rest of
my life.

And...how could I have forgotten that in "...." \n get understood. Jeez.
So easy.

Thanks for being there.

t.

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC
Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< (e-mail address removed) >> (email)
<< TomCloyd.com >> (website & psychotherapy weblog)
<< sleightmind.wordpress.com >> (mental health issues weblog)
<< directpathdesign.com >> (web site design & consultation)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top