3v4l.org

run code in 300+ PHP versions simultaneously
<?php //$s = "--included-- in package price: 5 % vat aed 10.00 destination fee per night 2 % municipality fee 3.5 % packaging fee 10 % warranty service charge breakfast"; $s = "--included-- in product price: breakfast --excluded--: 5 % vat aed 10.00 destination fee per night 2 % municipality fee 3.5 % packaging fee 10 % warranty service charge"; $results = []; if (preg_match_all('~(--(?:(?:not )?in|ex)cluded--)(?:\s+([a-zA-Z ]+))?:+\s*((?:(?!--(?:(?:not )?in|ex)cluded--).)*)~su', $s, $m, PREG_SET_ORDER, 0)) { foreach ($m as $v) { $lastline=array_pop($v); // Remove last item //print_r($details); if (preg_match_all('~(?:(\b(?:usd|aed|mad|usd)\b|\B€|\bus\$)\s*)?\d+(?:\.\d+)?(?:(?!(?1))\D)*~u', $lastline, $details)) { $results[] = array_merge($v, $details[0]); } else { $results[] = $v; } } //[3] => 5 % vat aed [4] => 10.00 destination fee per night //[3] => 5 % vat [4] => aed 10.00 destination fee per night } print_r($results);

preferences:
62.43 ms | 407 KiB | 5 Q