$re = '/[[:alpha:]]+[.!?]/m';
$str = 'For a given text file I\'d like to extract the final word in every sentence to a space-delimited text file. It would be acceptable to have a few errors for words like Mr. and Dr., so I don\'t need to try to achieve that level of precision.
I was thinking I could do this with Sed and Awk, but it\'s been too long since I\'ve worked with them and I don\'t remember where to begin. Help?';
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