fork download
  1. import re
  2. string = "<temp>The sale happened on February 22nd</temp>"
  3. res = re.sub('<temp>(.*?)</temp>', lambda m: "<temp>{}</temp>".format( m.group(1).replace(" on ", " {replace} ") ), string, flags=re.DOTALL)
  4. print(res)
Success #stdin #stdout 0.01s 9016KB
stdin
Standard input is empty
stdout
<temp>The sale happened {replace} February 22nd</temp>