title: Regex matching alphanumerics with possible dash in middle only
body: <p>I have managed to get this far:</p>
  
  <pre><code>^[a-zA-Z0-9]+(?:--?[a-zA-Z0-9]+)*$
  </code></pre>
  
  <p>but the above expression doesn't limit length as I need it to.  I need the pattern to only match 5-6 characters total.  So, this is how it ought to work out:</p>
  
  <pre><code>safety        (valid)
  safet-        (invalid)
  s-a-fe        (valid)
  -safet        (invalid)
  s7-45         (valid)
  s--fs         (invalid)
  </code></pre>
  
  <p>Consecutive hyphens are invalid.  Leading and trailing hyphens are invalid.  Overall length, which includes any hyphens, should be 5-6 characters.  I've tried replacing my <code>+</code>s with ranges (<code>{5,6}</code>), but no luck.  I appreciate any help.</p>
  
  <hr>
  
  <p>Another route I tried was:</p>
  
  <pre><code>^[A-Z0-9][A-Z0-9-]{3,4}[A-Z0-9]$i
  </code></pre>
  
  <p>which seems good and efficient, but it allows for consecutive hyphens.</p>