Re: gsub and regex
- From: Tom Cloyd <tomcloyd@xxxxxxxxxxx>
- Date: Wed, 18 Jun 2008 06:43:50 -0500
Stefano Crocco wrote:
On Wednesday 18 June 2008, Tom Cloyd wrote:Man, this list is absolutely amazing. Here I am programming at 4:30 in
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
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
<< tc@xxxxxxxxxxxx >> (email)
<< TomCloyd.com >> (website & psychotherapy weblog)
<< sleightmind.wordpress.com >> (mental health issues weblog)
<< directpathdesign.com >> (web site design & consultation)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.
- References:
- gsub and regex
- From: Tom Cloyd
- Re: gsub and regex
- From: Stefano Crocco
- gsub and regex
- Prev by Date: Re: Regular Expressions
- Next by Date: Re: quick question about how array objects are handled
- Previous by thread: Re: gsub and regex
- Next by thread: Using qt ruby
- Index(es):
Relevant Pages
|