I'm analyzing sales data I got from receipts. All bought items are in one column as one string like this:
'1 x Sandwich, "2 x Coffee, with cream", 1 x Apple pie'
I wish to separate all items to calculate the amount of items bought. A simple string.split(',') won't do, since there are also commas in the names of certain items. Luckily, these names are encapsulated by double quotes and 'normal' names are not.
How can I replace the commas within double quotes and not the commas separating items?
If these commas in names change into colons, for example, parsing the string can be done with string.split(). So the desired output will be something like this:
'1 x Sandwich, "2 x Coffee: with cream", 1 x Apple pie'
There might be other solutions, but this problem got me thinking about replacing very specific characters.
csvmodule should be able to parse that.