我有以下食材列表:
Ingredients <- "Starch (Corn | Potato | Wheat) | Vegetables (27%) [Pea (23%) (Flakes | Pieces) | Carrot Pieces | Onion Powder | Spinach Powder] | Croutons (10%) (Wheat Flour | Vegetable Oil | Salt | Yeast) | Maltodextrin | Natural Flavours (Contain Milk and Soybeans) | Creamer [Contains Milk | Mineral Salts (339 or 340 | 450 or 451)] | Salt | Mineral Salt (Potassium Chloride) | Sugar | Flavour Enhancer (621) | Vegetable Oil | Bacon Powder (0.5%) | Parsley | Natural Colour (Turmeric) | Burnt Sugar | Food Acid (Lactic) | Pepper Extract"
我想将它们分成一个数据框中的值,存储在变量ingredients
下。
但是我在编写代码时遇到了麻烦,因为列表中以各种方式使用分隔符|
。因此,我想在不包含括号()
或方括号[]
的情况下拆分|
。但我真的不知道如何处理这个问题。
也就是说,我们最终会得到一个配料值Starch (Corn | Potato | Wheat)
,另一个是Vegetables (27%) [Pea (23%) (Flakes | Pieces) | Carrot Pieces | Onion Powder | Spinach Powder]
,还有一个只是Salt
(还有其他成分,但对我来说前两个是比较棘手的情况)。