I'm trying to write a function to extract words that come before or after a group of phrases.
Extracting words that come after a single phrase, for example, item in a string variable called x, I had luck with the below code:
str_extract(x, pattern="(?<=item).*?(?=,)")
How do I pass on a list of phrases to look for onto a regex? For example, I want to create a list of phrases, called keywords and extract a group of words that come after these phrases. How do I tell regex keywords is a list, not a text?
keywords <- c("item",
"date",
"size",
"length")