title: Regex for Matching All Strings That Contain Two Different Words from a List
body: <p>I have need for a regular expression (in Java) that matches a string if and only if it contains two <b>different</b> words from a given list.</p>
  
  <p>For example, if the list of words is {blue,yellow,pink}, then the strings "blue and pink" and "yellow is the new blue" will match, but the strings "I like blue" will not (only one word from the list appears) and neither will the string "My pink shirt is so very pink" (it does not contain two or more different words, but the same word twice).</p>
  
  <p>The closest I could get to my desired regex is:</p>
  
  <p><code>(.<em>(blue|yellow|pink).</em>){2}</code></p>
  
  <p>This regex will match any string that contains two or more words from the list, but it will do so even if the two words are the same (as in the "My pink shirt is so very pink" example).</p>
  
  <p>Thanks!!</p>