From: Jens Wille Date: 2008-04-10T03:13:31+09:00 Subject: Re: capitalizing words hi peter! Peter Bailey [2008-04-09 20:04]: > Dir.chdir("C:/users/pb4072/documents") do |d| file = > File.read("test1.txt") output = > file.gsub(%r{^( face="b">)(.*)(<\/emph>)}m) do |match| > "#{$1}#{$2.gsub(%r{\b\w+\b}){|w|w.capitalize}}#{$3}" end > File.open("test1.txt", "w") { |f| f.write output } end > > Here's what I get. It works great, but, I don't understand why > the $3 text is simply blown away. because it's reset when you're doing that gsub on $2. the capture variables only refer to the *last* match. so you have to capture them into local variables first (can't think of a better way right now). cheers jens -- Jens Wille, Dipl.-Bibl. (FH) prometheus - Das verteilte digitale Bildarchiv f端r Forschung & Lehre Kunsthistorisches Institut der Universit辰t zu K旦ln Albertus-Magnus-Platz, D-50923 K旦ln Tel.: +49 (0)221 470-6668, E-Mail: jens.wille@uni-koeln.de http://www.prometheus-bildarchiv.de/