From: Morton Goldberg Date: 2006-07-22T02:28:01+09:00 Subject: Re: Replacing ' with \' using gsub irb(main):001:0> s = "a'b'" => "a'b'" irb(main):002:0> s.gsub(/'/, "\\\'") => "ab'b" irb(main):003:0> s.gsub(/'/, "\\\\\'") => "a\\'b\\'" Regards, Morton On Jul 21, 2006, at 1:04 PM, Jani Soila wrote: > I tried to replace "'" characters with "\'" strings using gsub. What > happened instead was something completely different. Am I missing > something here? > (in irb) > irb(main):001:0> s = "a'b'" > => "a'b'" > Unexpected result > irb(main):002:0> s.gsub(/'/, "\\'") > => "ab'b" > Also with this > irb(main):003:0> s.gsub(/'/, '\\\'') > => "ab'b" > However this works > irb(main):004:0> s.gsub(/'/, "\\x'") > => "a\\x'b\\x'" > > Thank you for your help! > -js > > -- > Posted via http://www.ruby-forum.com/. >