开发者

Replace urls with the shortened version - Ruby

开发者 https://www.devze.com 2022-12-20 20:34 出处:网络
Replacing the urls in a block of plain text is done by looking for url regular expressions. I开发者_Go百科 am using string.gsub(regex, \"\\1\") to achieve the same.

Replacing the urls in a block of plain text is done by looking for url regular expressions. I开发者_Go百科 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号