S
Sarah Allen
I'm trying to escape a URI that is matched by a regular expression with
gsub.
In irb, here's my string:=> "<a href='http://foo.com/one=>two'/>"
Now I want to match href="..." or href='...' and then URI.escape the
characters withing the quotes==> true
First I tried this:
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:
\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
gsub.
In irb, here's my string:=> "<a href='http://foo.com/one=>two'/>"
Now I want to match href="..." or href='...' and then URI.escape the
characters withing the quotes==> true
First I tried this:
=> "<a href='\#{URL.escape($2)}'/>"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:
=> "<a href=\001http://foo.com/one=%3Etwo\003'/>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