title: Matching prefix and multiple optional suffixes with no delimiter
body: <p>I'm trying to regex match strings that have a prefix and two optional suffixes that can come in any order, where the prefix and each suffix is grouped separately e.g.</p>
  
  <pre><code>input       =&gt; groups
  !attackH5E4 =&gt; (attack, H5, E4)
  !attackE4H5 =&gt; (attack, H5, E4)
  !HHHHHHH5   =&gt; (HHHHHH, H5, null)
  !HHHHHHH5E4 =&gt; (HHHHHH, H5, E4)
  !HHHHHHH5E4 =&gt; (HHHHHH, H5, E4)
  !HHHHHHH5E4 =&gt; (HHHHHH, H5, E4)
  </code></pre>
  
  <p>The regex pattern I'm currently using is</p>
  
  <pre><code>!([^\s]+)(?:(H\d+)|(E\d+)){0,2}
  </code></pre>
  
  <p>where group 1 is the prefix (e.g. <code>attack</code>), group 2 is the H-modifier (e.g. <code>H5</code>), and group 3 is the E-modifier (e.g. <code>E4</code>).</p>
  
  <p>As is, groups 2 and 3 get swallowed up by group 1. Throwing the <code>?</code> onto <code>[^\s]+</code> makes it match only the first character. Throwing <code>$</code> into the suffix non-capturing group doesn't work at all, unless I take off <code>{0,2}</code>.</p>
  
  <p><a href="http://regexr.com/3gbhj" rel="nofollow noreferrer">Here's a RegExr fiddle for the pattern, with test inputs and expected groups.</a></p>