My problem is this, there is a string
[word in IN ('hello', 'world'), key1=1100, key2=1200]
I need a list that would contain
[word in IN ('hello', 'world'),
key1=1100,
key2=1200
]
Obviously splitting by comma doesn't work, so went with regular expression grouping.
pattern= re.compile(r"(.*), [a-zA-Z]?", re.DOTALL)
string = "[word in IN ('hello', 'world'), key1=1100, key2=1200]"
for item in re.findall(pattern, string):
print item
What I am trying to do is to match only the commas after which space and an alphabet would occur, but for me, it giving wrong results.
[word in IN ('hello', 'world'), key1=1100
Still, it's greedy matching. Any help would be appreciated.