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
精彩评论