(I\'m using R.) For a list of words that\'s called \"goodwords.corpus\", I am looping through the documents in a corpus, and replacing each of the words on the list \"goodwo
Use \b
to indicate a word boundary:
> text <- "good night goodnight"
> gsub("\\bgood\\b", paste("good", 1234), text)
[1] "good 1234 night goodnight"
In your loop, something like this:
for (word in goodwords.corpus){
patt <- paste0('\\b', word, '\\b')
repl <- paste(word, "1234")
test <-gsub(patt, repl, test)
}