title: Regex to verify first and last character
body: <p>I need to verify in php that a string should not start or end with a hyphen <code>(-)</code>. The allowed characters are <code>a-z</code>, <code>A-Z</code>, <code>0-9</code> and a hyphen anywhere in the middle of the string. </p>
  
  <p>My this regex </p>
  
  <pre><code>/^[a-zA-Z0-9-]+$/
  </code></pre>
  
  <p>Verifies the occurrence of allowed character expect the condition that the string should not start or end with the hyphen. How do I achieve this? I new to regex.</p>