From: Jon Evans Date: 2008-04-30T22:10:09+09:00 Subject: Re: n00b string replace Hi, On Apr 30, 12:22 pm, theist...@gmail.com wrote: > How do I get "un \' monton \' de \' apostrofes \'" from "un ' monton ' > de ' apostrofes '"? using regex? Like this: >> st = "un ' monton ' de ' apostrofes '" => "un ' monton ' de ' apostrofes '" >> st.gsub(/'/, "\\\\'") => "un \\' monton \\' de \\' apostrofes \\'" It just displays with \\ in there because it needs to escape the \ itself when displaying it. Any manipulations you need to do on the actual string object will only see a single '\' character rather than a double. >> s = "'" => "'" >> s.gsub!(/'/, "\\\\'") => "\\'" >> s.length => 2 >> s[0].chr => "\\" >> s[1].chr => "'" Jon