0

I want to go through a column of a df and look to extract a substring out of the values in the column using a vector with several different possible matches. Is there a better way of getting this done with str_extract than:

str_extract(string, pattern1 | pattern2 | pattern3...)
Aarón Gzz
  • 99
  • 6

1 Answers1

1

We can use str_c to create a single string

library(stringr)
library(purrr)
pats <- reduce(mget(ls(pattern = '^pattern\\d+$')), str_c, collapse="|")
str_extract(string, pats)
akrun
  • 874,273
  • 37
  • 540
  • 662