Matching entire string in R

前端 未结 3 925
陌清茗
陌清茗 2021-01-25 00:33

Consider the following string:

string = \"I have #1 file and #11 folders\"

I would like to replace the pattern #1 with the word

3条回答
  •  温柔的废话
    2021-01-25 01:15

    Use the space after #1 to your advantage:

    gsub("#1 ", "one ", string, fixed = TRUE)
    
    [1] "I have one file and #11 folders"
    

提交回复
热议问题