On Apr 1, 2006, at 4:28 PM, petermichaux / gmail.com wrote: > > Chris Alfeld wrote: >> compressed = "foo = bar; red = herring;" >> compressed = compressed.gsub(/\s*([=;])\s*/,'\1') >> >> I believe #$1 is evalued *before* gsub is executed and hence fails. >> gsub sets the variable and uses \1, \2, \3 in the replacement string >> to correspond. > > Thank you! > > Peter > > If you want to use $1, $2, $3, etc. with gsub, you can use the block form: compressed.gsub(regexp) { |matched_string| $1 }