fork download
  1. actions <- c("taking","using")
  2. nouns <- c("medication","prescription")
  3. phrases <- c("he was using medication","medication using it","finding medication","taking the left","using prescription medication","taking medication drug")
  4. grep(paste0("(",paste(actions, collapse="|"), ")\\s+(", paste(nouns,collapse="|"),")"), phrases, value=FALSE)
  5. ## and a visual check
  6. grep(paste0("(",paste(actions, collapse="|"), ")\\s+(", paste(nouns,collapse="|"),")"), phrases, value=TRUE)
  7.  
Success #stdin #stdout 0.22s 60752KB
stdin
Standard input is empty
stdout
[1] 1 5 6
[1] "he was using medication"       "using prescription medication"
[3] "taking medication drug"