astring = '+(%S9)I(%S9,>,18,5010)V("C:/CTS/LIST.TXT",3,4,1,%S0,2,%S1,3,%S2,%S9)O(30)9,%S1W(4,V,5002)R(G1,%S2,20)I(%S2,=,1,5003)I(%S2,=,2,5004)I(%S2,=,3,5005)I(%S2,=," ",5006)' new_string = re.sub('>,\d+,', '>,%s,' % new_ver_from_file, astring) newest_string = re.sub('("\W+",', '("%s",' % use_file, new_string)