I have a table (pizza_orders) with a column called (ingredients) that looks like this:
order_no ingredients
1 cheese-olives-peppers-olives
2 cheese-olives
3 cheese-tomatoes-olives
4 cheese
I want to make 3 new variables:
- x1: everything from the start position to the first (e.g. cheese, cheese, cheese, cheese_
- x2: everything after the first – to the second – (e.g. olives, olives, tomatoes, NULL)
- x3: everything from the second – to the end position (e.g. peppers, NULL, olives, NULL)
I tried to use this link here to learn how to do it: https://www.ibm.com/docs/en/netezza?topic=ref-regexp-extract-2
SELECT
order_no,
ingredients,
REGEXP_EXTRACT(ingredients, '([^\-]*)', 1) AS x1,
REGEXP_EXTRACT(ingredients, '\-([^\-]*)', 1) AS x2,
REGEXP_EXTRACT(ingredients, '\-[^\-]*\-(.*)', 1) AS x3
FROM
pizza_orders;
x1 is coming out correctly, but x2 and x3 are not. Can someone help me correct the regex?