Reputation: 119
For ex: a.text has name "capybara" and I need to check whether the string has characters "ba" in it.
if a.text.contains?("ba")
# do something
else
# do something
end
Upvotes: 1
Views: 3082
Reputation: 1026
If you want more flexibility with regex, use match
like:
if a.text.match(/ba/)
# do something
end
Upvotes: 2
Reputation: 15967
text = "capybara"
text.include?("ba")
=> true
so you could do:
if text.include?("ba")
# do something
else
# do something else
end
Upvotes: 6