#!/usr/bin/ruby

#
## http://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character
#

func group(str) {
    gather {
        while (var match = (str =~ /((.)\g{-1}*)/g)) {
            take(match[0])
        }
    }
}

say group(ARGV[0] \\ 'gHHH5YY++///\\').join(', ')

assert_eq(group('gHHH5YY++///\\'), ["g", "HHH", "5", "YY", "++", "///", "\\"])
