title: python regex conditional in re.sub - how?
body: <p>Is it possible to use python's regex conditionals in <code>re.sub()</code>? I've tried a number of variations without luck. Here's what I have.</p>
  
  <pre><code>import re
  # match anything: &lt;test&gt; always true
  a = re.compile('(?P&lt;test&gt;.*)')  
  
  # return _'yes'_ or 'no' based on &lt;test&gt;
  a.sub('(?(\g&lt;test&gt;)yes|no)', 'word')
  '(?(word)yes|no)'
  </code></pre>
  
  <p>I expected either a 'yes' or 'no,' not the actual test.</p>
  
  <p>What I get from this is that <code>&lt;test&gt;</code> is seen but the regex conditional isn't being executed. Is there another way of accomplishing this?</p>
  
  <p>I tried with <code>re.sub(pat, rep, str)</code> with same results.</p>