Java:
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class IngredientExtractor {
public static void main(String[] args) {
String recipe = "Ingredients: 2 cups flour, 1 cup sugar, 1/2 cup butter, 1 tsp baking powder, 2 eggs, 1 cup milk";
List<String> ingredients = extractIngredients(recipe);
System.out.println("Extracted Ingredients: " + ingredients);
}
public static List<String> extractIngredients(String recipe) {
List<String> ingredients = new ArrayList<>();
String regex = "(\\d+\\s?\\d*\\/\\d*\\s?\\w+\\s\\w+)";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(recipe);
while (matcher.find()) {
ingredients.add(matcher.group(0));
}
return ingredients;
}
}
Shit in the aaaaaaaaass