Let’s say I have the following string:
here is some text in a sentence 55 and
some other text still in the same
sentence
There are two instances of the substring sentence in the string. How can I find the instance that is closest to the substring 55?
I am using Ruby 1.9.2
Split the string on the marker:
Distance from the second is simply via #index:
Distance from the first is slightly funkier:
Compare: