views:

50

answers:

1

Replacing the urls in a block of plain text is done by looking for url regular expressions. I am using string.gsub(regex, "\1") to achieve the same.

I would like to know how to proceed if the shortened url (using api's of any url shortening service) is to be used as the replacement and not the original url.

I am using Ruby.

+2  A: 
gsub(regex) {|url| shorten_url(url)}

Where shorten_url is a method that takes a url and returns a shorter url as a string suppled by a url shortening service.

EmFi
perfect! Never knew that gsub accepts a block. I should rtm more :) Thanks!
Vijay Dev