From: greg Date: 2006-11-06T10:28:27+09:00 Subject: Re: Ugly code - suggestions? couple of ideas for you- didn't this out though nil.to_s #=> "" no need to re-scan a match if you can use $1, $2, etc module ANSIParser ANSI_MATCH = /\e\[(\d+);(\d+)*m/ def self.ansi_to_array(str) str = str.to_s ret = [] str.scan(ANSI_MATCH) do |match| ret << $`.to_s << $1.to_i << $2.to_i end ret << $'.to_s end end sorry for using the Perl variables :) if you want you can use Regexp.last_match.post_match