I'm struggling to get a RegEx expression that matches all double-quote characters ("
) that occur within square brackets.
I have different pieces that do parts of what I want. For example,
gsub('"', "", '"""xyz"""')
[1] "xyz"
Will get all double-quotes, irrespective of anything else.
gsub('\\[(.*?)\\]', "", '[xyz][][][]abc')
[1] "abc"
Will get everything inside two square brackets, including the brackets themselves (which I do not want to happen -- how do I avoid that?).
I'm also not sure how to combine the two once I have them each working. Here's an example of the desired behavior. Given an input string ["cats", "dogs"]"x"
, I want an expression that will replace the four "
characters inside of the square brackets, but not the ones outside.
To be more specific:
gsub('THE_REGEX', "", '["cats", "dogs"]"x"')
should return
[cats, dogs]"x"
I want to remove double-quotes when they occur inside of square brackets, but not when they occur outside of square brackets.