Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing a Vimeo ID using JavaScript?

How do I parse an ID from a Vimeo URL in JavaScript?

The URL will be entered by a user, so I will need to check that they have entered it in the correct format.

I need the ID so that I can use their simple API to retrieve video data.

like image 899
Tom Avatar asked May 26 '10 20:05

Tom


2 Answers

regExp = /^.*(vimeo\.com\/)((channels\/[A-z]+\/)|(groups\/[A-z]+\/videos\/))?([0-9]+)/
parseUrl = regExp.exec url
return parseUrl[5]

This works for all valid Vimeo URLs which follows these patterns:

http://vimeo.com/*

http://vimeo.com/channels/*/*

http://vimeo.com/groups/*/videos/*

like image 198
Matilda Avatar answered Oct 20 '22 14:10

Matilda


As URLs for Vimeo videos are made up by http://vimeo.com/ followed by the numeric id, you could do the following

var url = "http://www.vimeo.com/7058755";
var regExp = /http:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/;

var match = url.match(regExp);

if (match){
    alert("id: " + match[2]);
}
else{
    alert("not a vimeo url");
}
like image 23
Sean Kinsey Avatar answered Oct 20 '22 14:10

Sean Kinsey