5

2 つのドル記号の間にない限り、すべてのバックスラッシュ\\を正規表現で置き換える必要があります。これら2つの文字の間にない限り、正規表現でこれらすべてを置き換えると言う方法がわかりません。\"\\$\\bar{x}$

これは、 2 ドルの内部でもgsubすべてを取り除く文字列と aです。\\

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"  

私が求めているのは:

## [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" 
4

2 に答える 2