I have the regex need to replace all backslashes \\
with \"
unless the \\
is between two dollar signs $\\bar{x}$
. I don't know how to say in regex replace all these unless it falls between these two characters.
Here's a string and a gsub
that gets rid og all \\
even inside double dollars
x <- c("I like \\the big\\ red \\dog\\ $\\hat + \\bar$, here it is $\\bar{x}$",
"I have $50 to \\spend\\", "$\\frac{4}{5}$ is nice", "$\\30\\ is nice too")
gsub("\\\\", "\"", x)
## > gsub("\\\\", "\"", x)
## [1] "I like \"the big\" red \"dog\" $\"hat + \"bar$, here it is $\"bar{x}$"
## [2] "I have $50 to \"spend\""
## [3] "$\"frac{4}{5}$ is nice"
## [4] "$\"30\" is nice too"
What I am after is:
## [1] "I like \"the big\" red \"dog\" $\\hat + \\bar$, here it is $\\bar{x}$"
## [2] "I have $50 to \"spend\""
## [3] "$\\frac{4}{5}$ is nice"
## [4] "$\"30\" is nice too"