title: Calling a function on captured group in re.sub()
body: <pre><code>&gt;&gt;&gt; base64_encode = lambda url : url.encode('base64').replace('\n', '')
  &gt;&gt;&gt; s = '&lt;A HREF="http://www.google.com" ID="test"&gt;blah&lt;/A&gt;'
  &gt;&gt;&gt; re.sub(r'(?&lt;=href=")([\w:/.]+)(?=")', base64_encode(r'\1'), s, flags=re.I)
  &lt;A HREF="XDE=" ID="test"&gt;blah&lt;/A&gt;
  </code></pre>
  
  <p>The base64 encoding of the string <code>http://www.google.com</code> is <code>aHR0cDovL3d3dy5nb29nbGUuY29t</code> not <code>XDE=</code>, which is the encoding of <code>\1</code>.</p>
  
  <p>How do I pass the captured group into the function?</p>