re = /.{1,5000}(?:\.|;)/
str = 'I need to modify the following script so that it says the following slogan
"Select 5000 characters (or, failing that, no more than 5000) from the string entered in the variable (Var), but stop at the last full stop or semicolon you find" (so, maybe select 4912 characters, for example)
In summary
up to 5000 (not beyond 5000)
but the limit to be selected is a full stop or a semicolon.
I think this should be done with a Regular Expression, but I don\'t know how I could do it;
Thank you very much in advance
'
# Print the match result
str.match(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