1
6 celery sticks, chopped
1 pear
300g/10.6oz strawberries
50g (1.7oz) porridge oats (uncooked)
1 tsp agave
100ml (3.4oz) Whole milk (soy/almond/rice/hemp/oat)
1 scoop of protein powder (approx. 20g/0.7oz)
½ avocado
100g/3.5oz of mushrooms, chopped
1 tsp extra virgin olive oil 

What I want to extract

celery sticks, pear, strawberries, porridge oats, agave, Whole milk, protein powder, avocado, mushrooms, extra virgin olive oil.

What I have tried

(^.*(\d|oz|\(|tsp|½|of)|(,|\().*$)

What I am getting

https://www.phpliveregex.com/p/rok

Click preg_split tab when you run it.

Ideally I should just be able to do match[0] and get the name.

1 Answer 1

2

You may use this regex in preg_match or preg_match_all functions:

^[\d½]+\S*\h+(?:\([^)]*\)|tsp|.*? of\b)?\h*([a-z]+(?:\h+[a-z]+)*)

RegEx Demo

RegEx Details:

  • ^: Start
  • [\d½]+: Match 1+ digits or ½
  • \S*: Match 0 or more non-space characters
  • \h+: Match 1+ horizontal spaces
  • (?:\([^)]*\)|tsp|.*? of\b)?\h*: Match extra bit of characters
  • ([a-z]+(?:\h+[a-z]+)*): Match ingredient name

PHP Live Demo

Sign up to request clarification or add additional context in comments.

1 Comment

Comments are not for extended discussion; this conversation has been moved to chat.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.