Ashok Padmanabhan Ashok Padmanabhan - 3 days ago 4
Vb.net Question

Is there a regex to match Facebook urls that contain videos or photos?

Is there a regex to match faebook url that have photos and/or videos? From what I can see such urls vary considerably. For example:

https://www.facebook.com/photo.php?v=827947030561502


https://www.facebook.com/idfonline/photos/a.250335824989295.62131.125249070831305/827806643908874/?type=1


The first contains a video and the 2nd a photo.

I have a regex for FB posts:
(?:https?:\/\/)?(?:www\.)?facebook\.com\/(?:(?:\w\.)*#!\/)?(?:pages\/)?(?:[\w\-\.]*\/)*([\w\-\.]*)


That regex works fine when I embed a post like
https://www.facebook.com/hnbot/posts/703129179742366
but not for things that have photo or video. So is it possible to have a regex for those posts with video or photos? This is all for the purposes of embedding FB posts.

Answer

This regex handles almost all facebook urls:

"((http:\/\/(www\.facebook\.com\/photo\.php.*|www\.facebook\.com\/video\/video\.php.*|www\.facebook\.com\/.*\/posts\/.*|fb\.me\/.*|www\.facebook\.com\/.*\/photos\/.*))|(https:\/\/(www\.facebook\.com\/photo\.php.*|www\.facebook\.com\/video\/video\.php.*|www\.facebook\.com\/.*\/posts\/.*|fb\.me\/.*|www\.facebook\.com\/.*\/photos\/.*)))"

It just doesnt handle something like https://www.facebook.com/idfonline/photos/a.250335824989295.62131.125249070831305/827806643908874/?type=1

Comments