On 30/09/05, Kev Jackson <kevin.jackson / it.fts-vn.com> 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
>
>

Nicest way to escape slashes is using a different regexp marker. I.e.

line.gsub!(%r{/}, '')

also be carefull to write either

line.gsub!(/a/, 'b')

or

line = line.gsub(/a/, 'b')

because gsub! does return nil if no substitution occured. E.g.

 "123".gsub!(/a/, 'b') # => nil

hope to help,

Brian

--
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/