<?php $inputs = [ '66 X, 55 Y, Z', '66 X, 55 Y,', '66 X, Z', '55 Y, Z', '66 X,', '55 Y', '44 Z' ]; foreach ($inputs as $input) { if (preg_match('~(?:(\d+) X,? ?)?(?:(\d+) Y)?~', $input, $out)) { echo (isset($out[1]) && $out[1] !== '') ? $out[1] : 'null'; // if zero is a project-impossibility, only use !empty() echo " - "; echo isset($out[2]) ? $out[2] : 'null'; echo "\t\t\t(from: $input)\n"; } }
You have javascript disabled. You will not be able to edit any code.