开发者

I need to match and expand a tiny url with javascript

I need to match and expand a tiny url with javascript:

http://开发者_StackOverflow中文版t.co/qJEZPFk

No luck with

    text.match(/http:\/\/t\.co.*/i)


You can use code like this to capture just the tiny URL code:

var url = "http://t.co/qJEZPFk";
var matches = url.match(/http:\/\/t\.co\/([^\/]+)\/?$/);
if (matches && matches.length > 1) {
    var urlCode = matches[1];
}

By way of explanation, the regex pattern is this:

  • http://t.co/
  • Followed by one or more characters that is not a / captured in a group
  • Followed by either a slash or the end of string
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜