func squeeze(str, c) { str.gsub(Regex("(" + c.escape + ")" + '\1+'), {|s1| s1 }) } var strings = ["", '"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln ', "..1111111111111111111111111111111111111111111111111111111111111117777888", "I never give 'em hell, I just tell the truth, and they think it's hell. ", " --- Harry S Truman ", "๐Ÿ˜๐Ÿ˜€๐Ÿ™Œ๐Ÿ’ƒ๐Ÿ˜๐Ÿ˜๐Ÿ˜๐Ÿ™Œ"] var squeeze_these = ["", "-", "7", ".", " -r", "๐Ÿ˜"] [strings, squeeze_these].zip {|str,st| say " original: ยซยซยซ#{str}ยปยปยป (length: #{str.len})" st.each {|c| var ssq = squeeze(str, c) say "'#{c}'-squeezed: ยซยซยซ#{ssq}ยปยปยป (length: #{ssq.len})" } say '' }