title: Regex to match optional character in any order
body: <p>I need to be able to match strings like:</p>
  
  <p><code>GQG6VJ6K</code>, <code>TYTU-TIDM-56</code>, <code>4-5-P-Z</code>, etc.</p>
  
  <p>The hyphen <code>-</code> is optional, but there must be at least one alphanumeric character.</p>
  
  <p>So far the best attempt I have come up with is <code>[A-Z0-9-]+</code> which wrongly matches a single hyphen.</p>
  
  <p>I also tried <code>(?[-]*)(?[A-Z0-9]+)</code> but it doesn't work (I'm a regex noob). Bonus points for why.</p>
  
  <p>What's the solution?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>@archeong87 led me to my final solution: <code>^[A-Z0-9]+(-{0,1}[A-Z0-9]+)*$</code></p>