s = gets.chomp.gsub(/^w/, '') cnt, longest = 0, 0 s.split('').each do |c| if c == 'w' cnt += 1 longest = longest < cnt ? cnt : longest else cnt = 0 end end if longest == 0 or longest == s.length puts exit true end regex = Regexp.new("[^w]+?w{#{longest}}") arr = s.scan(regex) if arr.length == 0 puts exit true end puts arr.map{|item| item.gsub(/w+/, '')}