Split string on the last occurrence of a character
regex, ruby, ruby-on-rails, split
Solution
Try simple code:
s = 'this sentence: should be: splited after last colon: sentence'
s =~ /(.*):(.*)?/
[ $1 << ':', $2 ]
# => ["this sentence: should be: splited after last colon:", " sentence"]
Problem
I have the string below: `this sentence: should be: split after last colon: sentence` I want to split the above string on the last colon (:) such that the resulting array will contain these two elements: ``` ["this sentence: should be: splited after last colon:", "sentence"] ```