My question is how to do what the answer of [this question][1] does, but only matching when the pattern ends with the end of the string.
my idea was adding $ after the pattern, to indicate the end of the line, exemple:
removePunctuation <- function(punctuationObject){
itemsToBeRemoved <- c(".", ",", ";", ":", "'", "!", "#", "-", "--")
resultObject <- punctuationObject
for (itemToReplace in itemsToBeRemoved){
resultObject <- gsub(itemToReplace$, "", resultObject, fixed = TRUE)
}
resultObject
}
but it doesnt work. i tried many variations of the same thing, but i cant get the $ to be read as regex after stating a variable pattern such as the 'itemToReplace'. [1]: For loop over list of items to use in R's gsub