title: How to extract words containing combinations of certain characters in R
body: <p>In this sample text:</p>
  
  <pre><code>turns &lt;- tolower(c("Does him good to stir him up now and again .", 
             "When , when I see him he w's on the settees .",
             "Yes it 's been eery for a long time .",
             "blissful timing , indeed it was "))
  </code></pre>
  
  <p>I'd like to extract all words that contain the letters <code>y</code> <strong>and</strong> <code>e</code> no matter what position or combination, namely <code>yes</code>and <code>eery</code>, using <code>str_extract</code> from <code>stringr</code>:</p>
  
  <p>This regex, in which I determine that <code>y</code> occur immediately before <code>e</code>, matches not surprisingly only <code>yes</code> but not <code>eery</code>:</p>
  
  <pre><code>unlist(str_extract_all(turns, "\\b([a-z]+)?ye([a-z]+)?\\b"))
  [1] "yes"
  </code></pre>
  
  <p>Putting <code>y</code>and <code>e</code> into a character class doesn't get me the desired result either in that all words <strong>either</strong> with <code>y</code> <strong>or</strong> with <code>e</code> are matched:</p>
  
  <pre><code>unlist(str_extract_all(turns, "\\b([a-z]+)?[ye]([a-z]+)?\\b")) 
   [1] "does"    "when"    "when"    "see"     "he"      "the"     "settees" "yes"     "been"    "eery"    "time"    "indeed" 
  </code></pre>
  
  <p>So what <strong>is</strong> the right solution?</p>