Search code examples
javascriptjqueryregexvimeo

Get Vimeo Id Using Embed Source -- JavaScript/Jquery


I want to get the Id of a Vimeo video using its Embed Source.

I want it in JavaScript OR jQuery.

I am using below code to do the same in PHP.

preg_match('/player\.vimeo\.com\/video\/([0-9]*)/', $embed, $match);

$vid = $match[1];

The above one is working fine. Is It possible to use above regex in javascript?

Here is a sample vimeo embed source -

<iframe src="http://player.vimeo.com/video/51478122?title=0&amp;byline=0&amp;portrait=0&amp;color=fcfcfc" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe> <p><a href="http://vimeo.com/51478122">Dum Spiro - HD (ESMA 2012)</a> from <a href="http://vimeo.com/dumspiro">Dum Spiro</a> on <a href="http://vimeo.com">Vimeo</a>.</p>

I want to extract 51478122 from this.

Any Help?


Solution

  • Sure, JavaScript supports regex as well >>

    var match = embed.match(/player\.vimeo\.com\/video\/([0-9]*)/);
    

    jsfiddle.net/XUDBL