evans.jon@gmail.com
4/30/2008 1:08:00 PM
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