From: Siep Korteling Date: 2010-12-09T10:07:57+09:00 Subject: Re: Splitting on capital letters 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 -- Posted via http://www.ruby-forum.com/.