import redef km_to_miles(match): return match/1.6print re.sub('(\d+)\ kilometers',str(int(lambda x:'%.2f miles (\\1 kms)' %km_to_miles(float(x.group(1))))), 'a distance of 17 kilometers.')#actually "a distance of 17 kilometers." is just an example, to simplify the script; i want to use stdin from bash and do this substitution in some web pages (i get the *text* output from links -dump)#NOTE: i want the regex to be as "transparent" as possible, so that i may modify it after the way i need. so i need to isolate the function from the rest of the regex as much as possible. actually, all i need to know how to substitute a certain captured string/number with some other string/number that is NOT preestablished by me BUT is returned by a function.