diff --git a/cookbook/helper/ingredient_parser.py b/cookbook/helper/ingredient_parser.py index 47e4058fd..cebae89c6 100644 --- a/cookbook/helper/ingredient_parser.py +++ b/cookbook/helper/ingredient_parser.py @@ -235,6 +235,10 @@ class IngredientParser: # leading spaces before commas result in extra tokens, clean them out ingredient = ingredient.replace(' ,', ',') + # handle "(from) - (to)" amounts by using the minimum amount and adding the range to the description + # "10.5 - 200 g XYZ" => "100 g XYZ (10.5 - 200)" + ingredient = re.sub("^(\d+|\d+[\\.,]\d+) - (\d+|\d+[\\.,]\d+) (.*)", "\\1 \\3 (\\1 - \\2)", ingredient) + # if amount and unit are connected add space in between if re.match('([0-9])+([A-z])+\s', ingredient): ingredient = re.sub(r'(?<=([a-z])|\d)(?=(?(1)\d|[a-z]))', ' ', ingredient)