From: Simon Strandgaard Date: 2005-10-18T01:41:51+09:00 Subject: Re: How to get non-unique elements from an array? On 10/17/05, pauldacus@gmail.com wrote: > Young grasshoppers... let us never forget the power of the REGEX! Let > us not bother with counters or blocks... let us GSUB this bad boy! > > a = [0,1,2,3,4,5,2,3] > > a.sort.to_s.gsub(/(.)(\1)+/, '').split(//) > > =>["0", "1", "4", "5"] no need to sort.. :-) a = [0, 1, 2, 3, 4, 5, 2, 3] a.to_s.delete(a.to_s.gsub(/(.)(?!.*\1)/,'')).split('').map{|i|i.to_i} #=> [0, 1, 4, 5] -- Simon Strandgaard