Comparing With Regular Expressions : String comparisons « String « Ruby
- Ruby
- String
- String comparisons
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