Text Manipulation : String comparisons « String « Ruby






Text Manipulation



letters = 'abcde'
puts letters =~ /a/
puts letters =~ /b/
puts letters =~ /e/
puts letters =~ /x/

letters = 'abcde'

puts letters =~ /aa?/
puts letters =~ /ax?/

letters = 'abcde'
puts letters =~ /ab?/
puts letters =~ /bc?/
puts letters =~ /b?/

 








Related examples in the same category

1.Comparing Strings
2.perform "greater than" and "less than" comparisons:
3.compare strings with the <=> method
4.A case-insensitive comparison is possible with casecmp, which has the same possible results as <=> (-1, 0, 1)
5.Comparing With Regular Expressions
6.string contains lowercase characters
7.string contains uppercase characters
8.string contains mixed case
9.string starts with a capital letter