def callback(match):
    return next(callback.v)
callback.v = iter(('1', '2', '3'))
s = 'blah blah blah'
print(re.sub('blah', callback, s))
Python regex: how to replace each instance of an occurrence with a different value?