title: How can I combine these two regexes?
body: <p>I would like to combine the following two regexes into one:</p>
  
  <ul>
  <li><code>^([A-Z]{1,2}) ?([0-9]{1,4})$</code> e.g. AB 1234</li>
  <li><code>^([0-9]{1,4}) ?([A-Z]{1,2})$</code> e.g. 1234 AB</li>
  </ul>
  
  <p>I thought this would be a simple as this:</p>
  
  <p><code>^([A-Z]{1,2}) ?([0-9]{1,4})|([0-9]{1,4}) ?([A-Z]{1,2})$</code></p>
  
  <p>However, the above always returns 4 groups, e.g.</p>
  
  <ol>
  <li><code>''</code></li>
  <li><code>''</code></li>
  <li><code>'1234'</code></li>
  <li><code>'AB'</code></li>
  </ol>
  
  <p>How can I combine these two regexes in a way that will always returns two groups? e.g.</p>
  
  <ol>
  <li><code>'1234'</code></li>
  <li><code>'AB'</code></li>
  </ol>
  
  <p>or</p>
  
  <ol>
  <li><code>'AB'</code></li>
  <li><code>'1234'</code></li>
  </ol>