From: "Milovan Z." Date: 2010-11-21T09:43:02+09:00 Subject: Re: Partial GSUB match / replacement You can use following regexp: string.gsub!(/(url\(['"]?)(.+?)(["']?\))/) { "#{$1}#{$2.upcase}#{$3}" } It is similar to yours with two differences: 1) I'm using (.+?) question mark here means that + is no longer greedy, it will match only to the point where next element in regexp is detected: and in your case that is either ", ' or ) 2) You cannot use functions on references like "\\2.capitalize" or "\\2".capitalize. It is just enterpreted as string. If you want to get matches as actual string representations, you should use a block. [http://ruby-doc.org/core/classes/String.html#M000817] hope this helps :) -- Posted via http://www.ruby-forum.com/.