title: How can I modify this regex to support multiple alternatives?
body: <p>im a newbie at constructing regex.</p>
  <p>I have this working regex:</p>
  <pre><code>^([a-zA-Z0-9\d]+-)*[a-zA-Z0-9\d]+$
  </code></pre>
  <p>Example:</p>
  <pre><code>-test : false 
  test- : false
  te--st : false
  test : true
  test-test : true 
  te-st-t : true 
  </code></pre>
  <p>I would like to add support for _ (underscores), so the above example replaced - to _ is the same result, but can only be one option only.</p>
  <p>Example:</p>
  <pre><code>te-st_test : false
  te_st_test : true
  </code></pre>
  <p>The solutions I tried:</p>
  <pre><code>^([a-zA-Z0-9\d]+(-|_))*[a-zA-Z0-9\d]+$
  
  ^(([a-zA-Z0-9\d]+-)|([a-zA-Z0-9\d]+_))*[a-zA-Z0-9\d]+$
  </code></pre>
  <p>Bad result:</p>
  <pre><code>te_st-test : true
  </code></pre>
  <p>I would like to have this result:</p>
  <pre><code>-test : false
  test- : false
  --test : false
  __test : false
  test-- : false
  test__ : false
  -_test : false
  test-_ : false
  test--test : false
  test__test : false
  test-_test : false
  te-st_test : false
  te-st : true
  te_st : true
  te_st_test : true
  te-st-test : true
  test : true
  </code></pre>
  <p><strong>Thanks &amp; have a nice day!</strong></p>