title: How to sub with matched groups and variables in Python
body: <p>new to python.  This is probably simple but I haven't found an answer.</p>
  
  <pre><code>rndStr = "20101215"
  rndStr2 = "20101216"
  str = "Looking at dates between 20110316 and 20110317"
  outstr = re.sub("(.+)([0-9]{8})(.+)([0-9]{8})",r'\1'+rndStr+r'\2'+rndStr2,str)
  </code></pre>
  
  <p>The output I'm looking for is:  </p>
  
  <pre><code>Looking at dates between 20101215 and 20101216
  </code></pre>
  
  <p>But instead I get:</p>
  
  <pre><code>P101215101216
  </code></pre>
  
  <p>The values of the two rndStr's doesn't really matter.  Assume its random or taken from user input (I put static vals here to keep it simple).  Thanks for any help.</p>