开发者

I need to match and expand a tiny url with javascript

开发者 https://www.devze.com 2023-04-01 02:27 出处:网络
I need to match and expand a tiny url with javascript: http://开发者_StackOverflow中文版t.co/qJEZPFk

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

精彩评论

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