本文介绍了使用JavaScript解析Vimeo ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在JavaScript中解析Vimeo网址中的ID?
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.
我需要ID才能使用他们的简单API来检索视频数据。
I need the ID so that I can use their simple API to retrieve video data.
推荐答案
由于Vimeo视频的网址由 http://vimeo.com/
后跟数字ID组成,可以执行以下操作
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");
}
这篇关于使用JavaScript解析Vimeo ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!