I have a bit of code for escaping double-quotes from a string which may include pre-escaped quotes; e.g:
This is a \"string"
Using the following code with Ruby 1.8.7p374:
string.gsub!(/([^\\])"/, '\1\"')
However, I get some funny edge-case when trying it on the following string: ab""c
=> ab\""c
. I would expect it to have escaped both quotes.
It's definitely not a big issue, but it got me curious.
Is this a mistake with my expression? A gsub
bug/feature?
(In newer Ruby versions, this could probably be solved easily by using negative lookbacks, but they seem to be not supported in this version).