I have a few million phrases to index so I don't want to loop through 
every phrase and test it with a regular expression.

Below is my working solution. Sometimes just describing the problem 
helps the brain to take a new approach:

text = "This is some text"
parts = text.split(/\W/)
phrases = []
parts.each_index do |s|
   s.upto(parts.size - 1){|e| phrases.push(parts.slice(s..e))}
end
phrases.each{|p| puts p.join(' ')}

Dan



James Edward Gray II wrote:
> On May 27, 2005, at 1:39 PM, Dan Fitzpatrick wrote:
> 
>> I am trying to build an indexing structure on some phrases. Most  
>> phrases will have 2 - 5 parts (words). The resulting array will be  
>> dumped into an index to find the matching phrases. I don't want to  do 
>> wildcard searching on the resulting array to find the phrase.
>>
>> I would like to turn "This is some text" into
>>
>> ["This",
>> "This is",
>> "This is some",
>> "This is some text",
>> "is",
>> "is some",
>> "is some text",
>> "some",
>> "some text",
>> "text"]
>>
>> The order of the resulting array doesn't matter. When someone  
>> searches for "is some" or "some text", I want it to find this  phrase. 
>> I don't want a search for "is text" to find this phrase  though.
> 
> 
> Perhaps I'm not understanding, but how does the following fail to  meet 
> your needs?
> 
> "This is some text".match(/is some/i)
> 
> James Edward Gray II
> 
>