title: How to substitute into a regular expression group in Python
body: <pre><code>&gt;&gt;&gt; s = 'foo: "apples", bar: "oranges"'
  &gt;&gt;&gt; pattern = 'foo: "(.*)"'
  </code></pre>
  
  <p>I want to be able to substitute into the group like this:</p>
  
  <pre><code>&gt;&gt;&gt; re.sub(pattern, 'pears', s, group=1)
  'foo: "pears", bar: "oranges"'
  </code></pre>
  
  <p>Is there a nice way to do this?</p>