Hi friends I am trying to search particular keywords (given in txt) in a list of files.I am using a regular expression to detect and replace the occurrence of the keyword in a file. Below is a comma separated keywords that i am passing to be searched.
library(stringi)
txt <- "automatically got activated,may be we download,network services,food quality is excellent"
Ex "automatically got activated" should be searched and replaced by automatically_got_activated..."may be we download" replaced by "may_be_we_download" and so on.
txt <- "automatically got activated,may be we download,network services,food quality is excellent"
for(i in 1:length(txt)) {
start <- head(strsplit(txt, split=" ")[[i]], 1) #finding the first word of the keyword
n <- stri_stats_latex(txt[i])[4] #number of words in the keyword
o <- tolower(regmatches(text, regexpr(paste0(start,"(?:[^a-zA-Z'-]+[a-zA-Z'-]+){0,",
n-1,"}"),text,ignore.case=TRUE))) #best match for keyword for the regex in the file
p <- which(!is.na(pmatch(txt, o))) #exact match for the keywords
}