T
theistian
Hi I'm triying to substitute any ocurrences of ' in a string by \'
Here's a bit of testing I made in irb which wtf's me:
irb(main):002:0> st = "un ' monton ' de ' apostrofes '"
=> "un ' monton ' de ' apostrofes '"
irb(main):003:0> sst = st.gsub(/'/,"\'")
=> "un ' monton ' de ' apostrofes '"
ok substitute ' by ' I don't know why interpeter interpret \' as
' when in a double-quoted string contex but I'm a newbie so sure I'm
wrong
irb(main):004:0> sst = st.gsub(/'/,"\\'")
=> "un monton ' de ' apostrofes ' monton de ' apostrofes ' de
apostrofes ' apostrofes "
irb(main):005:0> sst = st.gsub(/'/,"\\\'")
=> "un monton ' de ' apostrofes ' monton de ' apostrofes ' de
apostrofes ' apostrofes "
This seems to be substitute ' by "rest of string from ocurrence"
regardless of scape chars
Totally dazzed and desperate I tried with another backslash.... who
cares ... and get this
irb(main):006:0> sst = st.gsub(/'/,"\\\\'")
=> "un \\' monton \\' de \\' apostrofes \\'"
How do I get "un \' monton \' de \' apostrofes \'" from "un ' monton '
de ' apostrofes '"? using regex?
Thanks
Here's a bit of testing I made in irb which wtf's me:
irb(main):002:0> st = "un ' monton ' de ' apostrofes '"
=> "un ' monton ' de ' apostrofes '"
irb(main):003:0> sst = st.gsub(/'/,"\'")
=> "un ' monton ' de ' apostrofes '"
ok substitute ' by ' I don't know why interpeter interpret \' as
' when in a double-quoted string contex but I'm a newbie so sure I'm
wrong
irb(main):004:0> sst = st.gsub(/'/,"\\'")
=> "un monton ' de ' apostrofes ' monton de ' apostrofes ' de
apostrofes ' apostrofes "
irb(main):005:0> sst = st.gsub(/'/,"\\\'")
=> "un monton ' de ' apostrofes ' monton de ' apostrofes ' de
apostrofes ' apostrofes "
This seems to be substitute ' by "rest of string from ocurrence"
regardless of scape chars
Totally dazzed and desperate I tried with another backslash.... who
cares ... and get this
irb(main):006:0> sst = st.gsub(/'/,"\\\\'")
=> "un \\' monton \\' de \\' apostrofes \\'"
How do I get "un \' monton \' de \' apostrofes \'" from "un ' monton '
de ' apostrofes '"? using regex?
Thanks