re = /^.{0,79}?(?=\.(?:$| [A-Z]))\..+?(?=\.(?:$| [A-Z]))\.|^.{80,}?(?=\.(?:$| [A-Z]))\./m
str = 'First sentence; if first sentence <80 chars, get first 2 sentences.
The temperature was 32.8 degrees Celsius, his B.Sc. degree was deemed insufficient. The Dr. owed B. the bank USD 4000.50 which he had not paid back. On 27.07.2004 a major earthquake occurred. It was 17.05 by the clock.
First sentence if >80 chars, else get first 2 sentences if first sentence <80 chars
The temp was 32.8 C. His B.Sc. was insufficient.'
# 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