fork download
  1. import re
  2. text = "col1 = 'Test String' , col2= 'Next Test String',col3='Last Text String', col4=37"
  3. pattern = r"([^,\s=]+)\s*=\s*(?:'([^']*)'|(\S+))"
  4. matches = re.findall(pattern, text)
  5. print( dict([(x, z or y) for x,y,z in matches]) )
Success #stdin #stdout 0.03s 9492KB
stdin
Standard input is empty
stdout
{'col1': 'Test String', 'col2': 'Next Test String', 'col3': 'Last Text String', 'col4': '37'}