-1

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

http://t.co/qJEZPFk

No luck with

    text.match(/http:\/\/t\.co.*/i)
Jared
  • 11
  • 1

1 Answers1

0

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
jfriend00
  • 683,504
  • 96
  • 985
  • 979