From: "Peña, Botp" Date: 2007-08-13T13:22:20+09:00 Subject: Re: Split a string based on change of character From: James Edward Gray II [mailto:james@grayproductions.net] # >> require "strscan" # => true # >> scanner = StringScanner.new("ZBBBCZZ") # => # # >> char_runs = Array.new # => [] # >> char_runs << scanner.matched while scanner.scan(/(.)\1*/m) # => nil # >> char_runs # => ["Z", "BBB", "C", "ZZ"] i just started playing w string scan after getting a hint fr dblack and reading this rubyish example fr James. i think stringscanner is an ideal solution for string scanning related problems. I noticed that stringscanner#scan returns the match, so, irb> s = StringScanner.new("ZBBBCZZ") => irb> a=[] => [] irb> a << x while x=s.scan(/(.)\1*/m) => nil irb> a => ["Z", "BBB", "C", "ZZ"] again, short and readable. ruby rocks. kind regards -botp ps: stringscanner docs are here http://www.ruby-doc.org/stdlib/libdoc/strscan/rdoc/index.html