javascript - extract vimeo video id from the url -


though question available on so, facing little problem.i failed extract vimeo id using vimeo regex used here: vimeo regex

my codes i,m using now:

function vimeoprocess(url){    var vimeoreg = /https?:\/\/(?:www\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|)(\d+)(?:$|\/|\?)/;    var match = url.match(vimeoreg);    if (match){       console.log(match[3]);    }else{       return "<span class='error'>error</span>";    } } 

it not consoles thing. can 1 help?

this "magic regex" not magic. not work url you're using, instance.

here's parser set :

var urls =  [    "https://vimeo.com/11111111",    "http://vimeo.com/11111111",    "https://www.vimeo.com/11111111",    "http://www.vimeo.com/11111111",    "https://vimeo.com/channels/11111111",    "http://vimeo.com/channels/11111111",    "https://vimeo.com/channels/mychannel/11111111",    "http://vimeo.com/channels/yourchannel/11111111",    "https://vimeo.com/groups/name/videos/11111111",    "http://vimeo.com/groups/name/videos/11111111",    "https://vimeo.com/album/2222222/video/11111111",    "http://vimeo.com/album/2222222/video/11111111",    "https://vimeo.com/11111111?param=test",    "http://vimeo.com/11111111?param=test",    "http://vimeo.com/whatever/somethingelse/11111111?param=test",    "http://www.player.vimeo.com/stuff/otherstuff/11111111"  ];    $.each(urls, function(index, url) {          var firstpart = url.split('?')[0].split("/");    var vid = firstpart[firstpart.length - 1];            $("table").append('<tr><td>'+url+'</td><td><span>'+vid+'</span></td></tr>');  });
td   { font-family: monospace; }  span { background: lightgreen; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <table>      <tr><th>input</th><th>result</th></tr>  </table>

how works :

url.split('?') breaks "http://vimeo.com/whatever/somethingelse/11111111?param=test" ["http://vimeo.com/whatever/somethingelse/11111111","param=test"]

... or ["http://vimeo.com/whatever/somethingelse/11111111"] if there no ? in url.

now [0] takes first element of array, "http://vimeo.com/whatever/somethingelse/11111111".

then split using .split('/'), gives ["http:","","vimeo.com","whatever","somethingelse","11111111"]

now have take last element, our video id :

vid = firstpart[firstpart.length - 1] // gives "11111111" 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -