From: Alex Young Date: 2006-05-06T04:25:53+09:00 Subject: Re: Newbie question Kyle Alons wrote: > James Gray wrote: > >> >> ["&abc", "a&cb", "b&ac", "ccc", "cb&a"].grep(/&../) >>=> ["&abc", "a&cb", "b&ac"] >> >>Hope that helps. > > > That's not quite it. That seems to match all strings containing an > ampersand followed by 2 other characters. What I need is all strings > that have duplicate characters following an & (&a in the above). > Something a little more concrete: > > ["&File", "&Edit", "Vi&ew", "P&roject", "T&ree", "Favo&rites", "&Help"] > > would return > > ["&Edit", "Vi&ew", "P&roject", "T&ree", "Favo&rites"] > > (&e and &r are found multiple times). > keys = {} ["&File", "&Edit", "Vi&ew", "P&roject", "T&ree", "Favo&rites", "&Help"].each do |l| l =~ /&(.)/ (keys[ $1.downcase ] ||= []) << l end keys.values.select{|l| l.length > 1}.flatten There's almost certainly a better way... -- Alex