title: javascript regular expression match a string at some rules?
body: <p>My purpose is to find a function that checks if a string starts with a lower-case letter, ends with a lower-case letter, may contain only one or no hyphen <code>-</code>, and is less than or equal to 32 characters. </p>
  
  <p>The following is my code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var ss = /^[a-z]+([A-Za-z0-9_]|(-?)|[a-z]+$){1,31}/;
  str="ss-fjdkkldjkskjdskjdksjdkjdkjklskssdkdkffdkdfkdfk";
  ss.test(str);</code></pre>
  </div>
  </div>
  </p>
  
  <p>test string
  result with true
  aJDS-a a234bds aHJH878sjkJSK-ja</p>
  
  <p>My function is currently returning <code>true</code> and doesn't match my requirement.
  If the test string match reg requirement, the result should return true.
  I don't know why.</p>