fork(1) download
  1. import re
  2. r = r'{([\w\s,]+)}'
  3. s = "{Cat}\n{Cow Pig}\n{Cat,Dog}\ncat dog fish"
  4. print( re.sub(r, lambda x: "{{{}}}".format(re.sub(r'\w+', r'"\g<0>"', x.group(1))), s) )
Success #stdin #stdout 0.02s 27728KB
stdin
Standard input is empty
stdout
{"Cat"}
{"Cow" "Pig"}
{"Cat","Dog"}
cat dog fish