title: python back reference from regex like perl
body: <p>in perl you can do</p>
  
  <pre><code>if (/(.*)__(.*)/) {
     print "ans" . $1 . ' ' . $2 . "\n";
  }
  </code></pre>
  
  <p>in python, can you do the same?
  It seems like you can only do</p>
  
  <pre><code>m = re.match(r"(.*)__(.*),data)
  if m:
     print("ans {} {}".format(m[1],m[2]) 
  </code></pre>
  
  <p>Or is there better way to do this in more pythonic way?</p>
  
  <p>Anyway, if this is the way to go, then it's gonna really suck if you have lot of big if and elif to test against many different possible patterns. 
  I am really hoping someone who is more familiar w/ python can enlighten me</p>
  
  <p>in perl</p>
  
  <pre><code>if (/(.*)__(.*)/){
     #do another
  } elsif ( /(.*)XXX___(.*)/) {
     #do one thing
  }
  ......
  </code></pre>
  
  <p>Imagine I have many test cases. In python, how would I do that?</p>