From: Rory Pascua Date: 2011-09-14T23:05:23+09:00 Subject: Tough Ruby Homework I'm trying to take a long piece of text, find a word, and get that word and the 3 words on either side of it and put that new "string" into another variable. Example: I have a sentence like "Robert likes green beans, girls with moustaches, and teddy bears. John thinks Robert is strange". I am searching for the word "Robert", so I want to return the following: ["Robert likes green", "bears. John thinks Robert is strange."] (doesn't have to be in an array, but you get the idea) I obviously use index to get the places where "Robert" can be found, but any suggestion on how to do the rest? Bonus points: if you can do the same thing for multiple words...back to the example, but search for "green AND teddy"...you'd get: ["Robert likes green beans, girls", "with moustaches, and teddy bears. John thinks"] as a result. I'm posting this because I couldn't seem to find an easy way to do it.. -- Posted via http://www.ruby-forum.com/.