fork(3) download
  1. import re
  2. p = re.compile(r'(?<!")\b\w+\b(?!")')
  3. test_str = "{abc : \"xyz\", cde : {}, fgh : [\"hfz\"]}"
  4. print re.sub(p, r'"\g<0>"', test_str)
  5.  
  6. #Out of curiosity: perhaps, you can use `(?<!")\b\w+\b(?!")` and replace with `"\g<0>"`. See [this code](https://i...content-available-to-author-only...e.com/asSVPq)
Success #stdin #stdout 0.01s 7736KB
stdin
Standard input is empty
stdout
{"abc" : "xyz", "cde" : {}, "fgh" : ["hfz"]}