title: Regex to find 3 out of 4 conditions
body: <p>My client has requested that passwords on their system must following a specific set of validation rules, and I'm having great difficulty coming up with a "nice" regular expression.</p>
  
  <p>The rules I have been given are...</p>
  
  <ul>
  <li>Minimum of 8 character</li>
  <li>Allow any character</li>
  <li>Must have at least one instance from <strong>three of the four</strong> following character types...
  <ol>
  <li>Upper case character</li>
  <li>Lower case character</li>
  <li>Numeric digit</li>
  <li>"Special Character"</li>
  </ol></li>
  </ul>
  
  <p>When I pressed more, "Special Characters" are literally everything else (including spaces).</p>
  
  <p>I can easily check for at least one instance for all four, using the following...</p>
  
  <pre><code>^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?\d)(?=.*?[^a-zA-Z0-9]).{8,}$
  </code></pre>
  
  <p>The following works, but it's horrible and messy...</p>
  
  <pre><code>^((?=.*?[A-Z])(?=.*?[a-z])(?=.*?\d)|(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[^a-zA-Z0-9])|(?=.*?[A-Z])(?=.*?\d)(?=.*?[^a-zA-Z0-9])|(?=.*?[a-z])(?=.*?\d)(?=.*?[^a-zA-Z0-9])).{8,}$
  </code></pre>
  
  <p>So you don't have to work it out yourself, the above is checking for <code>(1,2,3|1,2,4|1,3,4|2,3,4)</code> which are the 4 possible combinations of the 4 groups (where the number relates to the "types" in the set of rules).</p>
  
  <p><strong>Is there a "nicer", cleaner or easier way of doing this?</strong></p>
  
  <p>(Please note, this is going to be used in an <code>&lt;asp:RegularExpressionValidator&gt;</code> control in an ASP.NET website, so therefore needs to be a valid regex for both .NET and javascript.)</p>