From: 7stud -- Date: 2008-06-02T04:33:55+09:00 Subject: Re: Remove Parts of a String Dan __ wrote: hen display the rating they've given. > > It seems to me that both yours and Stephano's solutions are equally > simple for what I'm using them for. I disagree. This solution is an abomination: str.gsub(/:[^,]*(?:$|(?=,))/,'').split( ',') Your problem is very simple. If you split() this string on commas: "12343:3,73820:1,183874:8" you get this array: ["12343:3", "73820:1", "183874:8"] Then you just have to split() each of the strings in the array, e.g "12343:3", on the colon: arr.each do |str| results = str.split(/:/) p results end Here it is altogether: str = "12343:3,73820:1,183874:8" arr = str.split(/,/) p arr arr.each do |str| results = str.split(/:/) p results end ["12343:3", "73820:1", "183874:8"] ["12343", "3"] ["73820", "1"] ["183874", "8"] Note: it's clearer to write split(",") but as is being discussed in another thread, the code will execute faster if you use a regex: split(/,/). If you specify an argument for split(), then use a regex rather than a string to make your code more efficient. If you value code clarity more than a slight improvement in efficiency, then use a string. -- Posted via http://www.ruby-forum.com/.