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())
