rep1 = '20101215'
rep2 = '20101216'
st = 'Looking at dates between 20110316 and 20110317'
print(re.sub('(?P<fp>.+)[0-9]{8}(?P<lp>.+)[0-9]{8}', '\\g<fp>' + rep1 +
    '\\g<lp>' + rep2, st))
How to sub with matched groups and variables in Python