title: Python regex matching whatever matched in previous group (1 out of multiple options)
body: <p>Lets say I have the regular expression <code>(?:AA|BB)(.*)(?:AA|BB)</code> which captures everything between the delimiters <code>AA</code> and <code>BB</code></p>
  
  <p>The problem I encounter is that this will also match <code>AA...BB</code></p>
  
  <p>How can I make it so that the regular expression only matches <code>AA...AA</code> and <code>BB...BB</code></p>