fork download
  1. text=c("hello, please keep THIS","THIS is important","all THIS should be done","not exactly This","not THHIS", "THAT is something I need, too")
  2. matches <- regmatches(text, gregexpr("\\b(THIS|THAT)\\b", text))
  3. res <- lapply(matches, function(x) if (length(x) == 0) NA else x)
  4. res[is.na(res)] <- ""
  5. unlist(res)
  6.  
Success #stdin #stdout 0.22s 60768KB
stdin
Standard input is empty
stdout
[1] "THIS" "THIS" "THIS" ""     ""     "THAT"