3v4l.org

run code in 300+ PHP versions simultaneously
<?php $re = '/(?:[0-9]+g|A handful).*?(?=\s*(?:[0-9]+g|A handful|$))/m'; $str = '35g walnut halves A handful of thyme leaves 200g portobello mushrooms 200g white mushrooms 200g chifferini pasta 100g Petit Brebis sheep\'s cheese 40g honey'; if (preg_match_all($re, $str, $matches)) { print_r($matches[0]); }

preferences:
28.23 ms | 405 KiB | 5 Q