title: Regex for [a-zA-Z0-9\-] with dashes allowed in between but not at the start or end
body: <h1>Update:</h1>
  
  <p>This question was an epic failure, but here's the working solution. It's based on Gumbo's answer (Gumbo's was close to working so I chose it as the accepted answer):</p>
  
  <h3>Solution:</h3>
  
  <pre><code>r'(?=[a-zA-Z0-9\-]{4,25}$)^[a-zA-Z0-9]+(\-[a-zA-Z0-9]+)*$'
  </code></pre>
  
  <h1>Original Question (albeit, after 3 edits)</h1>
  
  <p>I'm using Python and I'm <strong>not trying to extract the value</strong>, but rather test to make sure it fits the pattern.</p>
  
  <h2>allowed values:</h2>
  
  <pre><code>spam123-spam-eggs-eggs1
  spam123-eggs123
  spam
  1234
  eggs123
  </code></pre>
  
  <h2>Not allowed values:</h2>
  
  <pre><code>eggs1-
  -spam123
  spam--spam
  </code></pre>
  
  <p>I just can't have a dash at the starting or the end. There is <a href="https://stackoverflow.com/questions/703066/regex-to-trim-hyphens-from-start-and-end-of-a-string">a question on here</a> that works in the opposite direction by getting the string value after the fact, but I simply need to test for the value so that I can disallow it. Also, it can be a <strong>maximum of 25 chars long</strong>, but <strong>a minimum of 4 chars long</strong>. Also, <strong>no 2 dashes can touch each other</strong>.</p>
  
  <p>Here's what I've come up with after some experimentation with lookbehind, etc:</p>
  
  <pre><code># Nothing here
  </code></pre>