This is my string:
msgid """We couldn't set up that account, sorry. Please try again, or contact an ""admin (link is above)."
I want to remove all the double quotes except the first and last one. How may I do that?
This is my string:
msgid """We couldn't set up that account, sorry. Please try again, or contact an ""admin (link is above)."
I want to remove all the double quotes except the first and last one. How may I do that?
Here is an option as long as you know you always want a quote at the beginning and at the end.
Assume x is holding the sting you want to manipulate.
x = '"' + x.gsub('"', '') + '"'
This is assuming your strings will always be of the "msgid..." format shown above and your inteded output was 'msgid "text here"':
>> str.gsub(/(msgid )"{1,}(.*) "{1,}(.*)"/, '\1"\2 \3"')
=> "msgid "We couldn't set up that account, sorry. Please try again or contact an admin (link is above).""
>> puts str.gsub(/(msgid )"{1,}(.*) "{1,}(.*)"/, '\1"\2 \3"')
msgid "We couldn't set up that account, sorry. Please try again or contact an admin (link is above)."
I'd go with something like this:
msg = %q{msgid """We couldn't set up that account, sorry. Please try again, or contact an ""admin (link is above)."} print 'msgid "' << msg.sub('msgid ', '').gsub('"', '') << '"' # >> msgid "We couldn't set up that account, sorry. Please try again, or contact an admin (link is above)."
If "msgid" precedes every line, then remove it, deal with the double-quotes by stripping them, then put back "msgid" and add the desired leading and trailing double-quotes again.