On Oct 30, 2005, at 9:02 AM, William James wrote: > The people on Ruby Core who are trying to speed up CSV parsing > could use this as a starting point. My latest offering to Ruby Core has been: def parse_csv( data ) io = if data.is_a?(IO) then data else StringIO.new(data) end line = "" loop do line += io.gets parse = line.dup parse.chomp! csv = if parse.sub!(/\A,+/, "") then [nil] * $&.length else Array.new end parse.gsub!(/\G(?:^|,)(?:"((?>[^"]*)(?>""[^"]*)*)"|([^",]*))/) do csv << if $1.nil? if $2 == "" then nil else $2 end else $1.gsub('""', '"') end "" end break csv if parse.empty? end end Which is passing all the edge cases they have thrown at it so far and is very similar to the speed you achieved. James Edward Gray II