R-从字符串中删除引号之间的文本

R-从字符串中删除引号之间的文本,r,regex,stringr,grepl,R,Regex,Stringr,Grepl,我有很多行,每一行都是单独处理的(这里不需要循环)。以下是我的台词示例: "warning(\"Failed to parse headers:\\n\", paste0(bad, \"\\n\"), call. = FALSE)" "}" "names <- vapply(pieces, \"[[\", 2, FUN.VALUE = character(1))" &qu

我有很多行,每一行都是单独处理的(这里不需要循环)。以下是我的台词示例:

"warning(\"Failed to parse headers:\\n\", paste0(bad, \"\\n\"), call. = FALSE)"
"}"
"names <- vapply(pieces, \"[[\", 2, FUN.VALUE = character(1))"
"new_response <- grepl(\"^HTTP\", lines)"
"header_lines <- lines[lines != \'\'][-1]"
我的问题是,一些引号(我不知道如何调用引号内的“位”)可能与正则表达式匹配,然后
mgsub
无法找到它们

有问题的例子:

"names <- vapply(pieces, \"[[\", 2, FUN.VALUE = character(1))"
编辑:预期输出将是(对于上面的每一行,有问题的情况在中间):

“警告(,粘贴0(错误,),调用=FALSE)”
"}"
“名称
gsub(“[\”].*?['\”],“”,a)
[1] 警告(,粘贴0(错误,),调用=FALSE)
[2] "}"                                                     

[3] “命名预期的输出是什么?
gsub(“[\”].[\”],“”,您的字符串)
?@onyanbu我刚刚添加了预期的输出。您放置的gsub未按预期工作。
"names <- vapply(pieces, \"[[\", 2, FUN.VALUE = character(1))"
 Error in gregexpr(pattern[i], string, ...) : 
  invalid regular expression '"[["', reason 'Missing ']'' 
"warning(, paste0(bad, ), call. = FALSE)"
"}"
"names <- vapply(pieces, , 2, FUN.VALUE = character(1))"
"new_response <- grepl(, lines)"
"header_lines <- lines[lines != ][-1]"
gsub("[\"'].*?['\"]","", a)

[1] "warning(, paste0(bad, ), call. = FALSE)"               
[2] "}"                                                     
[3] "names <- vapply(pieces, , 2, FUN.VALUE = character(1))"
[4] "new_response <- grepl(, lines)"                        
[5] "header_lines <- lines[lines != ][-1]"  
a <- c("warning(\"Failed to parse headers:\\n\", paste0(bad, \"\\n\"), call. = FALSE)", 
        "}", "names <- vapply(pieces, \"[[\", 2, FUN.VALUE = character(1))", 
        "new_response <- grepl(\"^HTTP\", lines)", "header_lines <- lines[lines != ''] [-1]")