Hi ,
I trying to search and replace all urls on a HTML string using gsub .
CODE
html = "<a href='http://site.com.br'><img src='http://site3.com/ image.jpg'></a><a href='http://newx.com.br'><img src='http://localhost/ imagem.jpg'></a>";
pattern = /<a href=[\'"]?([^\'"> ]*)[\'"]?[^>]*>(.*?)<\/a>/mo
replace = "<a href='http://mysite.com/redirect/#\{$1\}'>\#\{$2\}</a>"
html_output = html.gsub(pattern,replace)
The REGEX pattern is apparently working but I 'm not getting the values of $1 and $2 . When I use \\1 and \\2 it works . Thing is ... I need to encode $1 variable like this replace = "<a href='http://mysite.com/redirect/#\{Base64.encode64 ($1)}'>#{$2}</a>"
and I not able to encode \\1
Can anyone help me ?