Parsing a Vimeo ID using JavaScript?
If you want to check for Vimeo URL first:
function getVimeoId( url ) {
// Look for a string with 'vimeo', then whatever, then a
// forward slash and a group of digits.
var match = /vimeo.*\/(\d+)/i.exec( url );
// If the match isn't null (i.e. it matched)
if ( match ) {
// The grouped/matched digits from the regex
return match[1];
}
}
E.g.
getVimeoId('http://vimeo.com/11918221');
returns
11918221
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/*
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");
}