Consider the following string:
string = \"I have #1 file and #11 folders\"
I would like to replace the pattern #1 with the word
#1
Use the space after #1 to your advantage:
gsub("#1 ", "one ", string, fixed = TRUE) [1] "I have one file and #11 folders"