Loose search term possible?

I’m parsing through yaml files and I am trying to find a specific word,
but i’d also like return true if the word exists in a a much larger word
for instance

return true if tie is in bowtie or hellotiehello.

I am using .include?(“tie”) and it returns true for single words
matching but not the word embedded in a larger word. How can I go about
doing this?

hi Richard,

maybe #match would work?

strings = [“tie”, “bowtie”, “funkymonkey”]
strings.each{|entry| p entry if entry.match(‘tie’)}

=>“tie”
=>“bowtie”

  • j

Richard S. wrote in post #1002856:

I’m parsing through yaml files and I am trying to find a specific word,
but i’d also like return true if the word exists in a a much larger word
for instance

return true if tie is in bowtie or hellotiehello.

I am using .include?(“tie”) and it returns true for single words
matching but not the word embedded in a larger word. How can I go about
doing this?

That’s what regular expressions(regex’s) do:

arr = [
‘tie’,
‘bowtie’,
‘xxxTIEyyy’,
‘TiEmeup’,
‘nomatch’,
]

regex = /tie/i

arr.each do |word|
if word.match(regex)
puts word
end
end

–output:–
tie
bowtie
xxxTIEyyy
TiEmeup

‘i’ means ‘ignore case’.