Comparing With Regular Expressions : String comparisons « String « Ruby






Comparing With Regular Expressions


string = 'This is a 30-character string.'

if string =~ /([0-9]+)-character/ and $1.to_i == string.length
  "Yes, there are #$1 characters in that string."
end

 








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.string contains lowercase characters
6.string contains uppercase characters
7.string contains mixed case
8.string starts with a capital letter
9.Text Manipulation