fork download
  1. import re
  2.  
  3. string = "Foo \n value of something \n Bar \n Another value \n"
  4. changewords = ["foo", "Bar"]
  5.  
  6. tem = string
  7. for i in changewords:
  8. tem = re.sub(f'(?i){i} \n', f'{i}:', tem)
  9. print( tem )
  10.  
Success #stdin #stdout 0.02s 9480KB
stdin
Standard input is empty
stdout
foo: value of something 
 Bar: Another value