From: Mike Stok Date: 2010-01-26T03:02:44+09:00 Subject: Re: gsub problem On Jan 25, 2010, at 12:50 PM, lalawawa wrote: > Seebs wrote: >> On 2010-01-25, lalawawa wrote: >>> irb(main):005:0> a.gsub(/([\'\?])/, '\\\\\1') >>> => "Can\\'t we\\?" >> This is probably what you want -- keep in mind that irb will show >> you escaped backslashes if there's a single backslash in the string. >> -s > > You're right. > > irb(main):009:0> puts a.gsub(/([\'\?])/, '\\\\\1') > Can\'t we\? > => nil > irb(main):010:0> > > Thanks You can get rid of a few backslashes if you like: $ irb --simple-prompt >> a = "Can't we?" => "Can't we?" >> puts a.gsub(/['?]/) { |c| "\\#{c}" } Can\'t we\? => nil Mike -- Mike Stok http://www.stok.ca/~mike/ The "`Stok' disclaimers" apply.