From: "Peña, Botp" Date: 2008-09-02T19:21:22+09:00 Subject: Re: escaping ' From: John Pritchard-williams [mailto:monojohnny@googlemail.com] # David Nguyen wrote: # > I need to replace ' by \'. How can I do that? # This was harder than I thought...in "vi"(vim actually) I just had to: # 1,$ s/'/\\'/g # But Ruby didn't seem to like that.... # Anyway, for reasons unknown to me, this works: how i wish the behaviour would change. search the archives. this is a faq :) # puts "'hello'".gsub("'","\\\\'") if like me, you want to lessen the those fences :) try, "'hello'".gsub("'") { "\\'" } #=> "\\'hello\\'" or "'hello'".gsub "'", %q[\\\'] #=> "\\'hello\\'" for obvious reason, my brain prefers the former kind regards -botp