Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Get full sentence for query

View gist:1324770
1 2 3 4 5 6 7 8 9 10
> text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.'
> query = 'veniam'
> pos = text =~ /#{query}/
=> 142
> prev_period = text.rindex('.', pos) || -1
=> 123
> next_period = text.index('.', pos) || -1
=> 231
> sentence = text[prev_period+1..next_period]
=> " Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.