title: Selecting columns with fixed pattern at beginning and end of name, and variable middle part
body: <p>I want to <code>select</code> data frame columns that have a certain pattern at the beginning and the end of their names, and one out of several possible values in the middle. This is what works, but I find the double use of <code>intersect</code> not very elegant. </p>
  
  <pre><code>df &lt;- data.frame(var1_one_num = sample(1:10, 10, replace = TRUE),
                   var1_two_num = sample(1:10, 10, replace = TRUE),
                   var1_three_num = sample(1:10, 10, replace = TRUE),
                   var1_four_num = sample(1:10, 10, replace = TRUE),
                   var2_one_num = sample(1:10, 10, replace = TRUE),
                   var1_one_fac = sample(1:10, 10, replace = TRUE))
  
  var_middle &lt;- c("one|two|three")
  
  df %&gt;% select(intersect(starts_with("var1_"),
                          intersect(matches(var_middle),
                                    ends_with("_num")))) %&gt;% names()
  
  [1] "var1_one_num"   "var1_two_num"   "var1_three_num"
  </code></pre>
  
  <p>I suspect there is smarter way with <code>any of</code> or similar, but I could not get round it.</p>