$re = '/^(?:(\d+)\sYears?)?,?\s?(?:and\s)?(?:(\d+)\sMonths?)?,?\s?(?:and\s)?(?:(\d+)\sDays?)?$/mi';
$str = '3 Years, 1 Month, and 60 Days
2 Months, and 1 Day
3 Days
1 Month
5 Years, and 2 Months
7 Years, and 1 Day
1 Year, 1 Month, and 1 Day
700';
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