I am trying to replace the strings with special characters using gsub. But I am running into error invalid regular expression '\bc++\b', reason 'Invalid use of repetition operators'.
df = data.frame("word"=c('c++', '.XLS','Java-prog'))
for i in nrow(df){
df$new[i] <- gsub(paste0("\\b", df$word[i], "\\b"), "xx", df$new[i],ignore.case = T)
}
Actual code:
data = data.frame("word"=c('python', 'java'),
"description"=c('Java-script is a statically typed and Python py is a dynamically typed',
'java is a programming language'), stringsAsFactors = FALSE)
ll <- as.list(data$word)
data$new <- data$description
for(i in seq_len(nrow(data))) for(j in seq_along(ll)) {
data$new[i] <- gsub(paste0("\\b", ll[j], "\\b"), "url", data$new[i],ignore.case = T)
}
The expectation is to replace the values with xx.