Sample input:
\"I was 09809 home -- Yes! yes! You was\"
and output:
{ \'yes\' => 2, \'was\' => 2, \'i\' => 1, \'home\
This works, and ignores the numbers:
def get_words(my_str) my_str = my_str.scan(/\w+/) h = Hash.new(0) my_str.each do |s| s = s.downcase if s !~ /^[0-9]*\.?[0-9]+$/ h[s] += 1 end end return h end print get_words('I was there 1000 !') puts '\n'