$re = '/X(\d+\.\d+)(?:Y(\d+\.\d+))?|Y(\d+\.\d+)/m';
$str = 'G1X445.71Y602.47
G1X446.11
G1Y601.91
G1X445.73Y602.26S76.5F300';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php