Use python re.sub instead of sed.