text = gets.chomp # text = "うはwwwwwおkwwwww" text = text.gsub(/^[w]+/, "") w_array = text.scan(/[w]+/) max_w = w_array.sort_by(&:length).last.length for word in text.scan(/[^w]+[w]{#{max_w}}/) p word.gsub(/[w]+/, "") end