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?'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html