Replace text between two special characters

后端 未结 2 569
醉话见心
醉话见心 2021-01-20 06:47

I have a character vector as:

x<- \"\\t\\t\"

and

 y<- \"TOT_A01\"

相关标签:
2条回答
  • 2021-01-20 07:38

    I would use something like

    gsub("\".*\"", paste0("\"", y, "\""), x)
    

    It just means "find text within two quotation marks in x and replace it with y inside two quotation marks"

    I think this is what you want, your example is wrong though

    0 讨论(0)
  • 2021-01-20 07:39

    Try

     sub('(?<=").*(?=")', y, x, perl=TRUE)
     #[1] "\t\t<taxon id=\"TOT_A01\"/>"
    
    0 讨论(0)
提交回复
热议问题