Farhan Salam Farhan Salam - 3 months ago 7
Ruby Question

Replace inner double quotes in a string in an array

I have strings in an array:


I am using
method to form an array with this string, but the inner double quotes are not escaped:

eval('["foo","bar","foo"bar"baz"]') # => SyntaxError

Is there a way to escape only the ones inside an array element?


I think you can try something like

eval('["foo","bar","foo"bar"baz"]'.gsub(/(\w)\"(\w)/, '\1\"\2'))

if I got what you have meant