Robin C Samuel
Robin C Samuel

Reputation: 1225

Retrieve video id from facebook video url

I wan't to get the facebook video id from urls. I noticed video urls in multiple formats.

https://www.facebook.com/username/videos/vb.100000724987616/709948045706022/?type=2&theater

https://www.facebook.com/username/videos/426337427566302/?theater

https://www.facebook.com/photo.php?v=426337427566302&type=2&theater

Can anyone share a regex to retrieve the id from above urls ?

Upvotes: 0

Views: 2614

Answers (1)

Andrey Korneyev
Andrey Korneyev

Reputation: 26886

To match a url like this: https://www.facebook.com/username/videos/10154470513168574

You can use /(\d+)\/?$/ pattern - one ore more digits \d+ followed by optional slash \/? at the end of line $.

See example.

Upvotes: 3

Related Questions