fork download
  1. import re
  2.  
  3. pattern = r"(\"[^\"]* cost\":\s*)\"(\d{1,3}(?:\.\d{1,2})?)\""
  4.  
  5. s = ("\"apple cost\": \"2.78\" \n"
  6. "\"orange cost\": \"12.59\"\n"
  7. "\"melone cost\": \"42.12\"")
  8.  
  9. print(re.sub(pattern, r"\1\2", s))
  10.  
Success #stdin #stdout 0.04s 9520KB
stdin
Standard input is empty
stdout
"apple cost": 2.78 
"orange cost": 12.59
"melone cost": 42.12