title: How to capture one of two things, then the other of two things
body: <p>This is a generic regular expression question, that I couldn't find an answer too.</p>
  
  <p>Lets say I have a few input strings:</p>
  
  <pre><code>...A-A-B...
  ...B-A-A...
  ...A-B-A...
  ...B-B-A...
  </code></pre>
  
  <p>I have two delimiters <code>A</code> and <code>B</code>. What I want to do is find either of these, and then look for the other one. Now I know I can do <code>(A.*B)|(B.*A)</code> which will match what I want for all four strings.</p>
  
  <p>And I can also do <code>(A|B).*\1</code> which would match <code>A-A</code> for the first and second strings, <code>A-B-A</code> for the third and <code>B-B</code> for the last.</p>
  
  <p><strong>Can I do something alongs the lines of <code>(A|B).*[^\1]</code> to say, find one of two tokens then find the other token?</strong></p>
  
  <p>For context, I was interested in this because of <a href="https://stackoverflow.com/questions/18646862/regex-allows-one-character-it-should-not-why/18647499#18647499">this question</a>, where <code>A</code> and <code>B</code> are a dot or comma for currency matching, but I figure this could be useful in lots of contexts, hence the generic question.</p>