title: Regex to validate hypen(-) at start and end of the string
body: <p>I'm validating a string("-test-") whether it contains hypens(-) at start and end of the string using regex. So i found an regex to restrict hypen at start and end of regex.</p>
  
  <pre><code>/^(?!-)[a-zA-Z0-9-' ]+[^-]$/i
  </code></pre>
  
  <p>This regex was validating as expected when the string contains more than one char("aa") with or without hypen. But its not working as expected when i'm simply passing one character string("a") without hypen.</p>
  
  <p>And also these need to allow special characters and alphanumeric characters like "$abcd&amp;". Need to restirct oly hypen at start and end of the string.</p>
  
  <p>Could you guys help out of this..</p>