0

Is there a regex to match facebook 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.

lepe
  • 24,677
  • 9
  • 99
  • 108
Ashok Padmanabhan
  • 2,110
  • 1
  • 19
  • 36

1 Answers1

0

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

Ashok Padmanabhan
  • 2,110
  • 1
  • 19
  • 36