I have a set of character vectors:
a <- "bmi + ch | study"
b <- "bmi * ch | study"
c <- "bmi * ch - 1 | study"
d <- "bmi * ch + 0 | study"
e <- "bmi:ch + 0 | study"
In this example, I want to extract the two strings "bmi" and "ch", i.e. the desired output is c("bmi", "ch")
The strings above are just examples; the character elements to be extracted can be anything else other than ch and bmi. I'm looking for a general solution, without hard-coding.
I have tried unlist(stringr::str_extract_all(a, "bmi|ch")). However, here I manually define the pattern "bmi|ch" to achieve the desired output. Thus, it's not a general solution.