Re: ruby gsub! problem
- From: "William James" <w_a_x_man@xxxxxxxxx>
- Date: 30 Sep 2005 00:22:12 -0700
Kev Jackson wrote:
> Hi all,
>
> I need to escape / in a gsub!
>
> eg
>
> line = line.gsub!(///, '')
>
> Unfortunately I don't know how to escape the / (forward slash) - the
> data I'm munging has this in it (annoyingly)
>
> Kev
If you use this method, you don't need to escape the slashes:
"09/30/05".sub( %r{(\d\d)/(\d\d)/(\d\d)}, '\3-\1-\2')
"09/30/05".sub( %r!(\d\d)/(\d\d)/(\d\d)!, '\3-\1-\2')
"09/30/05".sub( %r](\d\d)/(\d\d)/(\d\d)], '\3-\1-\2')
.
- Follow-Ups:
- Re: ruby gsub! problem
- From: Kev Jackson
- Re: ruby gsub! problem
- Prev by Date: Re: [ANN] Rapid GUI Development with QtRuby
- Next by Date: Re: Operator Overloading <<
- Previous by thread: Threading Performance?
- Next by thread: Re: ruby gsub! problem
- Index(es):
Relevant Pages
|