text = gets.chomp # text = "wwwwww" text = text.gsub(/^[w]+/, "") w_array = text.scan(/[w]+/) if text == "" or w_array.length == 0 p "" return 0 end max_w = w_array.sort_by(&:length).last.length for word in text.scan(/[^w]+[w]{#{max_w}}/) p word.gsub(/[w]+/, "") end