Let's say I have a vector like this
foo <- c('est','bel','cat')
and then I have a line like:
str <- "test"
How can I get "est" for a refund
library(stringr) foo[str_detect(str, foo)] #> [1] "est"
And when multiple valid substrings appear:
foo <- c('est','bel','cat', 'tes') foo[str_detect(str, foo)] #> [1] "est" "tes"
which(sapply(foo, (function(x) grepl(x, str)))==T)