fork download
  1. import re
  2. Ingredient = 'Beef stock (beef bones, water, onion, carrot, beef meat, parsnip, thyme, parsley, clove, black pepper, bay leaf), low lactose cream (28%), onion, mustard, modified maize starch,tomato puree, modified potato starch, butter sugar, salt (0,8%), burnt sugar, blackcurrant, peppercorns (black, pink, green, all spice, white) 0,4%.'
  3. res = re.sub(r'\s*\([^()]*\)[^,]*(?:,\b[^,]*)*', "", Ingredient)
  4. print(re.split(r',\s*', res))
  5.  
  6. vals = re.findall(r'\([^()]*\)|([^\W\d]+(?:\s+[^\W\d]+)*)', Ingredient)
  7. vals = [x for x in vals if x]
  8. print(vals)
Success #stdin #stdout 0.01s 9024KB
stdin
Standard input is empty
stdout
['Beef stock', 'low lactose cream', 'onion', 'mustard', 'modified maize starch', 'tomato puree', 'modified potato starch', 'butter sugar', 'salt', 'burnt sugar', 'blackcurrant', 'peppercorns']
['Beef stock', 'low lactose cream', 'onion', 'mustard', 'modified maize starch', 'tomato puree', 'modified potato starch', 'butter sugar', 'salt', 'burnt sugar', 'blackcurrant', 'peppercorns']