title: Regular Expression for Password Strength Validation
body: <p>I have written a regular expression which could potentially be used for password strength validation:</p>
  
  <pre><code>^(?:([A-Z])*([a-z])*(\d)*(\W)*){8,12}$
  </code></pre>
  
  <p>The expression consists of four groups:</p>
  
  <ol>
  <li>Zero or more uppercase characters</li>
  <li>Zero or more lowercase characters</li>
  <li>Zero or more decimal digits</li>
  <li>Zero or more non-word characters (!, £, $, %, etc.)</li>
  </ol>
  
  <p>The way I want it to work is to determine how many of the groups have been matched in order to determine the strength of the password. so for example, if only 1 group is matched, it would be weak. If all four groups were matched, it would be strong.</p>
  
  <p>I have tested the expression using <a href="http://rubular.com/" rel="noreferrer">Rubular (a Ruby regular expression editor).</a></p>
  
  <p>Here I can see visually, how many groups are matched, but I want to do this in JavaScript. I wrote a script that returns the number of matched groups, but the results were not the same as I can see in Rubular.</p>
  
  <p>How can I achieve this in JavaScript? and is my regular expression up to the task?</p>