Finding if a sentence contains a specific phrase in Ruby
Posted
by
TenJack
on Stack Overflow
See other posts from Stack Overflow
or by TenJack
Published on 2011-01-13T22:37:42Z
Indexed on
2011/01/14
0:53 UTC
Read the original article
Hit count: 206
Right now I am seeing if a sentence contains a specific word by splitting the sentence into an array and then doing an include to see if it contains the word. Something like:
"This is my awesome sentence.".split(" ").include?('awesome')
But I'm wondering what the fastest way to do this with a phrase is. Like if I wanted to see if the sentence "This is my awesome sentence." contains the phrase "my awesome sentence". I am scraping sentences and comparing a very large number of phrases, so speed is somewhat important.
© Stack Overflow or respective owner