this is the closest answer I can come up with
gsub /(url\(['"]?)([^\)'"]+)(['"]?\))/, "\\1#{"\\2".capitalize}\\3"
or
gsub /(url\(['"]?)([^\)'"]+)(['"]?\))/, "\\1\\2.capitalize\\3"
but neither of these solutions work
It doen't have to be with gsub, I just thought this would be the most
straightforward way
this is the closest answer I can come up with
gsub /(url\(['"]?)([^\)'"]+)(['"]?\))/, "\\1#{"\\2".capitalize}\\3"
or
gsub /(url\(['"]?)([^\)'"]+)(['"]?\))/, "\\1\\2.capitalize\\3"
but neither of these solutions work
It doen't have to be with gsub, I just thought this would be the most
straightforward way
ideas?
You can use a block with gsub, where the back-references are
accessible via the $1, $2, etc:
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.
this is the closest answer I can come up with
gsub /(url\(['"]?)([^\)'"]+)(['"]?\))/, "\\1#{"\\2".capitalize}\\3"
or
gsub /(url\(['"]?)([^\)'"]+)(['"]?\))/, "\\1\\2.capitalize\\3"
but neither of these solutions work
It doen't have to be with gsub, I just thought this would be the most
straightforward way
Although the last example by w_a_x_man looks efficient and simpler, I
needed a very specific match, as it actually matching
(http://www.google.com) and not even considering the url, then just
trying to capitalize the parentheses.
I went with
"url(http://www.google.com)".sub /(url\(['"]?)([^\)'"]+)(['"]?\))/,
"#{$1}#{$2.upcase}#{$3}"