re = /[A-Z]\S*\.[^\S\r\n]+[A-Z]|(?:^|[.!?][\t ]+)([A-Z]\S*)/m
str = 'We went to Dr. Smith\'s office
This is a proper sentence. It is followed by another sentence. What happens when an abbreviation like NASA enters the scene? What about N.A.S.A with the dots in between?
It is NASA! No one will convince me otherwise!
N.A.S.A. at the start of a sentence? N.A.S.A. immediately after?
At the end of the sentence: NASA. But also with the dots: N.A.S.A. Filler sentence here.
The compromise of catching situations like Dr. Smith is that words at the end of a sentence cannot start with a capital letter.
While This Regex Doesn\'t Match Every Word As The Start Of A Sentence Here, It Won\'t Detect The Start Of The Next Sentence. Case in point.
Abbreviations like LIKE currently pose a problem.
The second regex has false negatives: it will fail to match `So` in `This is sentence is English. So is this one.`
'
# 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