title: How do I differentiate a group reference from a number that follows it?
body: <p>I'm attempting to replace all occurances of a particular number within a string. For example, lets say I want to replace specific instances of a given number with another:</p>
  
  <pre><code>&gt;&gt;&gt; number1 = 33
  &gt;&gt;&gt; number2 = 1
  &gt;&gt;&gt; re.sub('(foo)%i' % number1, '\\1%i' % number2, 'foo33')
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in ?
    File "/home/david_clymer/Development/VistaShare/ot_git/lib/python2.4/sre.py", line 142, in sub
      return _compile(pattern, 0).sub(repl, string, count)
    File "/home/david_clymer/Development/VistaShare/ot_git/lib/python2.4/sre.py", line 260, in filter
      return sre_parse.expand_template(template, match)
    File "/home/david_clymer/Development/VistaShare/ot_git/lib/python2.4/sre_parse.py", line 784, in expand_template
      raise error, "invalid group reference"
  sre_constants.error: invalid group reference
  &gt;&gt;&gt; re.sub('(foo)%i' % number1, '\\1 %i' % number2, 'foo33')
  'foo 1'
  </code></pre>
  
  <p>How can I keep the group reference from being conflated with the following number?</p>