From: Mike Stok Date: 2006-02-06T07:18:46+09:00 Subject: Re: regex trick On 5-Feb-06, at 5:08 PM, Alain FELER wrote: > I want to replace all ' by \' ? (I need it to do inserts in mysql). > > s = "j'ai" > > s.gsub!(/'/,'\'') > > p s ==> gives j'ai and not j\'ai as I want > Thanks for help. s.gsub!(/'/, "\\\\'") or s.gsub!(/'/) { "\\'" } will do what you want Hope this helps, Mike -- Mike Stok http://www.stok.co.uk/~mike/ The "`Stok' disclaimers" apply.