import re
file = "Dear John Buy 1 of A1~A10, cost 10 dollars\n Ivan Buy 20 of Milk\nDear Tina Buy 10 of Coke, cost 100 dollars\n Mary Buy 5 of Milk"
for line in file.split("\n"):
match = re.search(r'\s+(?P<name>\w+)\D*(?P<num>\d+)\sof\s(?P<item>[^,]+)\D*(?P<costs>\d*)',line)
if match:
print(match.groups())
aW1wb3J0IHJlCmZpbGUgPSAiRGVhciAgIEpvaG4gICAgQnV5ICAgMSBvZiBBMX5BMTAsIGNvc3QgMTAgZG9sbGFyc1xuICAgICAgIEl2YW4gICAgQnV5ICAyMCBvZiBNaWxrXG5EZWFyICAgVGluYSAgICBCdXkgIDEwIG9mIENva2UsIGNvc3QgMTAwIGRvbGxhcnNcbiAgICAgICBNYXJ5ICAgIEJ1eSAgIDUgb2YgTWlsayIKZm9yIGxpbmUgaW4gZmlsZS5zcGxpdCgiXG4iKToKCW1hdGNoID0gcmUuc2VhcmNoKHInXHMrKD9QPG5hbWU+XHcrKVxEKig/UDxudW0+XGQrKVxzb2Zccyg/UDxpdGVtPlteLF0rKVxEKig/UDxjb3N0cz5cZCopJyxsaW5lKQoJaWYgbWF0Y2g6CgkJcHJpbnQobWF0Y2guZ3JvdXBzKCkpCg==
('John', '1', 'A1~A10', '10')
('Ivan', '20', 'Milk', '')
('Tina', '10', 'Coke', '100')
('Mary', '5', 'Milk', '')