Ruby Is a string present within another string (using a regexp)?

Is there a present? method in ruby to check if a string is present within an other? I'd want to return as soon as a match is found since I will be checking for multiple substrings. Thanks!


ANSWERS:


I believe you mean include?


I believe you are looking for include?

"ab123de".include?("123")

include?


Sorry, found what i was looking for (because of the use of regexp):

index(regexp [, offset]) → fixnum or nil

Returns the index of the first occurrence of the given substring or pattern (regexp) in str. Returns nil if not found.

"hello".index('lo')            #=> 3
"hello".index('a')             #=> nil
"hello".index(?e)              #=> 1
"hello".index(/[aeiou]/, -3)   #=> 4

i just used a loop checking if the index is nil



 MORE:


 ? How to count a string elements' occurrence in another string in ruby?
 ? Convert String to Regexp in Ruby
 ? Array includes string ruby?
 ? How do I check if a string contains a specific word?
 ? How do I check if a string contains a specific word?
 ? How do I check if a string contains a specific word?
 ? PHP - How to check if a string contain any text
 ? PHP - How to check if a string contain any text
 ? PHP - How to check if a string contain any text
 ? PHP - How to check if a string contain any text