Cagatay Gurturk
Cagatay Gurturk

Reputation: 7246

Detect facebook video URLs with Javascript

How can I detect a Facebook video URL by Javascript?

Upvotes: 0

Views: 1469

Answers (2)

Mohan
Mohan

Reputation: 1

Regex Reg=new Regex(@"^http(?:s?):\/\/www\.facebook\.com\/video.php\?v=(\d+)");

Just Remoeved the / before ^http and at last of URL.

I it modified like this for using in C#... it worked for me!

Upvotes: 0

rayfranco
rayfranco

Reputation: 3690

I think this is a pretty bad way to get it done, but facebook videos should match something like this :

var url   = "https://www.facebook.com/photo.php?v=7489378947389&set=t.674367&type=3&theater";
var regex = /^http(?:s?):\/\/www\.facebook\.com\/photo.php\?v=(\d+)/;

if (url.match(regex))
    alert('This is a neat facebook video !')

If I say this is a bad way to achieve this, it's because facebook keep changing their url, I've never seen something constant on their side. Youtube URL are a way more reliable, for example.

This regex should work as facebook format their video URL today, and maybe will not in a few month.

Upvotes: 1

Related Questions