Ashwini Agarwal
Ashwini Agarwal

Reputation: 4858

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?

Upvotes: 0

Views: 2964

Answers (2)

Ωmega
Ωmega

Reputation: 43673

Sure, JavaScript supports regex as well >>

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

jsfiddle.net/XUDBL

Upvotes: 2

Soarabh
Soarabh

Reputation: 2950

As per your requirement I am fetching src from Iframe and extracting the Vimeo video Id. Solved using jQuery

please have a look.

DEMO

http://jsfiddle.net/saorabhkr/XKvY6/1/

Upvotes: 0

Related Questions