From: Sam Duncan Date: 2010-12-09T10:18:40+09:00 Subject: Re: Splitting on capital letters Very nice =] On 09/12/10 14:07, Siep Korteling wrote: > Sam Duncan wrote in post #967298: > >> This might be ridiculous, but ... >> >> ("BenefitsAndFeatures".gsub(/[A-Z]/) { |c| "-#{c}" >> }).reverse.chomp('-').reverse >> >> Sam >> > Eliminating the reverse.chomp.reverse: > > "BenefitsAndFeatures".gsub(/\w(?=[A-Z])/){|match| "#{match}-"} > > the (?=[A-Z]) bit is a positive lookahead; the regex matches a word > character followed by a capital, without making the capital part of the > match. > > hth, > > Siep > >