title: How do I write a regex to replace a word but keep its case in Python?
body: <p>Is this even possible?</p>
  
  <p>Basically, I want to turn these two calls to sub into a single call:</p>
  
  <pre><code>re.sub(r'\bAword\b', 'Bword', mystring)
  re.sub(r'\baword\b', 'bword', mystring)
  </code></pre>
  
  <p>What I'd really like is some sort of conditional substitution notation like:</p>
  
  <pre><code>re.sub(r'\b([Aa])word\b', '(?1=A:B,a:b)word')
  </code></pre>
  
  <p>I only care about the capitalization of the first character.  None of the others.</p>