From: Joel VanderWerf Date: 2002-07-13T15:15:18+09:00 Subject: Re: gsub() replacement containing replaced text Harry Ohlsen wrote: > I want to replace all single quotes in a string with backslask followed by a > single quote. The obvious approach doesn't seem to work, presumably because > the replacement contains the pattern that's been replaced. One way (learned this in a post here a few days ago): irb(main):001:0> "foo'bar".gsub("'", "\\'") "foobarbar" irb(main):002:0> "foo'bar".gsub("'") {"\\'"} "foo\\'bar"