From: Sarah Allen Date: 2009-05-11T08:52:09+09:00 Subject: gsub pattern substitution and ${...} I'm trying to escape a URI that is matched by a regular expression with gsub. In irb, here's my string: >> s = "" => "" Now I want to match href="..." or href='...' and then URI.escape the characters withing the quotes >> require URI ==> true First I tried this: >> s.gsub(/href=(['"])([^']*)/, 'href=\1#{URL.escape($2)}\3') => "" Of course, that doesn't work since ${expr} will only eval the expression within a double quoted string. But when it is double quoted, like this: >> s.gsub(/href=(['"])([^']*)/, "href=\1#{URI.escape($2)}\3") => " \1 doesn't evaluate to the first match anymore I would guess there's some basic string or regex syntax that I'm missing here. I've looked at the gsub and string documentation, and either I missed it or I should be looking elsewhere. Can someone give me a clue and help me move forward with my mother's day hacking session? Thanks in advance, Sarah -- Posted via http://www.ruby-forum.com/.