I am trying to replace all incidents of a certain number inside a string. For example, let's say I want to replace individual instances of a given number with another:
>>> number1 = 33 >>> number2 = 1 >>> re.sub('(foo)%i' % number1, '\\1%i' % number2, 'foo33') Traceback (most recent call last): File "<stdin>", 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 >>> re.sub('(foo)%i' % number1, '\\1 %i' % number2, 'foo33') 'foo 1'
How can I save a link to a group with the following number?
source share