use a method called match, provided by the String class : match « String « Ruby






use a method called match, provided by the String class

puts "String has vowels" if "This is a test".match(/[aeiou]/)

 








Related examples in the same category

1.match doesn't require a regular expression as an argument, it converts any string supplied into a regular expression
2.if you surround a section with (), the data matched is made available separately from the rest.
3.The String class has the =~ method and the !~ operator.
4.The !~ operator returns true if it does not match the string, false otherwise:
5.Pattern matching with regular expressions