title: regex: how match []something|[]some?
body: <p>I'm trying write a regex which can match this</p>
  
  <blockquote>
    <p>[]something|some|...</p>
  </blockquote>
  
  <p>so basically needs match words and/or array characters [] and match any number of options/types (could be 2 or many more)</p>
  
  <p>I try this</p>
  
  <pre><code>(\[?\]?\w+\||\|\[?\]?\w+)
  </code></pre>
  
  <p>but this fails because if it match the <code>|</code> character with the first regex can't comeback for match the <code>|</code> character in the beginning of the second option <code>|\|\[?\]?\w+</code></p>
  
  <p>i would like capture only the types in expressions like this</p>
  
  <pre><code>function blah(a: []something|[]some|blah)
  </code></pre>
  
  <p>match only</p>
  
  <pre><code>1) []something
  2) []some
  3) blah
  </code></pre>
  
  <p>thanks</p>