Vimeo video link regex
Anybody got the regex for vimeo video links to extract them from a pragraph for use in php? Can't seem to find a proper one for the la开发者_运维问答test vimeo url scheme
Vimeo have 4 different public video links
- Video ID
vimeo.com/[Video ID]
- Channels
vimeo.com/channels/[Channel]/[Video ID]
- Groups
vimeo.com/groups/[Group]/[Video ID]
- Player
player.vimeo.com/video/[Video ID]
/(http|https)?:\/\/(www\.|player\.)?vimeo\.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|video\/|)(\d+)(?:|\/\?)/
As far as I can tell, the scheme is just http://vimeo.com/A_NUMBER
, so try http://(www\.)?vimeo\.com/(\d+)
. If you don't need links to be prefixed by http://
, you can leave off the whole http://(www\.)
bit.
Be careful: The url scheme is
http://vimeo.com/[SEVERAL_FOLDERS(opt.)]/[VIDEO_NUMBER]
for example:
http://vimeo.com/channels/staffpicks/48237094
http://vimeo.com/48237094
As you can see, it depends from what page the user copies the link from.
This one covers all possible Vimeo Video URL Schemes:
(?:http|https)?:?\/?\/?(?:www\.)?(?:player\.)?vimeo\.com\/(?:channels\/(?:\w+\/)?|groups\/(?:[^\/]*)\/videos\/|video\/|)(\d+)(?:|\/\?)
vimeo.com/123456789
vimeo.com/channels/mychannel/123456789
vimeo.com/groups/shortfilms/videos/123456789
player.vimeo.com/video/123456789
http://vimeo.com/123456789
https://vimeo.com/channels/mychannel/123456789
https://vimeo.com/groups/shortfilms/videos/123456789
https://www.player.vimeo.com/video/123456789
Test here: https://regexr.com/68gk3
Is there anything wrong with vimeo\.com/(\d)+
? Do you need the http://www.
?
It's Better to ask viemo guys about it because they know better and if they change anything they will reflect it in their apis
Live Example :
http://vimeo.com/api/oembed.json?url=http%3A//vimeo.com/76979871
API docs : http://developer.vimeo.com/apis/oembed
Answer inspired from this one https://stackoverflow.com/a/17156853/1545904
精彩评论