I'm trying to replace any duplicated letter with a one letter.
I use gsub
here and it's working:
text <- c("This tree is veeeeery tall")
gsub("([a-zA-Z])\\1+", "\\1", text)
##[1] "This tre is very tal"
BUT I need to make exception for some words to be like this:
"This tree is very tall"
I tried the solution in this question Here but it doesn't work.
text <- c("This tree is veeeeery tall")
words2keep <- c("tree", "tall")
gsub(perl=T,paste0('(?!\\b',paste(collapse='\\b|\\b',words2keep),'\\b)\\b([a-zA-Z])\\1+\\b'),'\\1',text)
##[1] "This tree is veeeeery tall"
So, is there any way to do it?