From: Renaud HEBERT Date: 2001-08-06T18:46:58+09:00 Subject: [ruby-talk:19200] Re: Some remarks from a nembie in Ruby Lloyd Zusman wrote: > ts writes: > >>>>>> "R" == Renaud HEBERT writes: > >R> [ ... ] > >R> > >R> 4) To replace a single backslash with two, you need to write gsub(/\\/, > >R> '\\\\\\\\')!! Ouch! > > > > http://www.rubycentral.com/faq/rubyfaq-9.html#ss9.18 > > > > You can write '\&\&', only 4 characters > > But to replace the letter 'a' with two backslashes, you still have ... > > gsub(/a/, '\\\\\\\\') > > However, you can also do this: > > gsub(/\\/){'\\\\'} > > and > > gsub(/a/){'\\\\'} > > > Guy Decoux > > -- > Lloyd Zusman > ljz@asfast.com In fact, it is not the length or the '\\\\\\\\' strings needed and I know that there are some work-arounds. Still I think that it is a PITFALL: naturally when trying to replace \ by \\, knowing that '\' are escaped characters, you would write: gsub(/\\/,'\\\\'). The need to either write gsub(/\\/,'\\\\\\\\') or use a work-around gsub(/\\/){'\\\\'}, indicates (for me) than something is broken.. -- Renaud Hebert phone: (33) 01 30 77 59 92 mailto:renaud.hebert@alcatel.fr