title: match regular expression using regex order, not string order in JavaScript
body: <p>I'm looking to extract a specific pattern from a string, and <strong>if its not there</strong> then extract another pattern. </p>
  
  <p>The string in question may have both patterns in any order. Regardless of the order, I want the first pattern to take priority. </p>
  
  <p>I know I could do this with multiple lines/<code>match</code> calls but I am wondering if it is possible to do this with a single <code>match</code> call.</p>
  
  <pre><code>var s1 = "hello A123 B456"
  var s2 = "hello B123 A456"
  </code></pre>
  
  <p>I want to capture <code>A###</code> pattern first, <strong>and only if its not there</strong>, then capture the <code>B###</code> pattern</p>
  
  <pre><code>console.log(s1.match(/((A|B)\d{3})/)[1]); // A123
  console.log(s2.match(/((A|B)\d{3})/)[1]); // B123 -- but I want it to capture the A123 first
  </code></pre>