input = gets.chomp output = [] max = 0 matches = input.scan(/(.*?)(w+)/) matches.each do |md| size = md[1].size next if md[0].size == 0 if size > max max = size output = [md[0]] elsif size == max output << md[0] end end puts output