Reputation: 394
I have a string like this
string = 'Company Bla potato text 123 random foo bar'
How can I detect including string in string?
string.include?('potato') => true
string.include?('Company Bla') => true
this work fine but how I can detect these cases:
string.include?('Potato') => false
string.include?('Company BLA') => false
string.include?('RANDOM') => false
they return false but I need true.
Upvotes: 0
Views: 326
Reputation: 80065
s = "Company BLA"
p string.match?(/#{s}/i)
The trailing i
tells the regex to ignore case.
Upvotes: 3
Reputation: 30056
One simple way is to make both downcase or uppercase
s = 'Potato'
string.downcase.include?(s.downcase)
Upvotes: 6