1
votes

I'm trying to distinguish between whether a given Facebook URL is a post or a video.

Luckily, Facebook lists the possible URLs for both posts and videos:

Posts:

  • https://www.facebook.com/{page-name}/posts/{post-id}>
  • https://www.facebook.com/{username}/posts/{post-id}>
  • https://www.facebook.com/{username}/activity/{activity-id}>
  • https://www.facebook.com/photo.php?fbid={photo-id}>

  • https://www.facebook.com/photos/{photo-id}>

  • https://www.facebook.com/permalink.php?story_fbid={post-id}>
  • https://www.facebook.com/media/set?set={set-id}>
  • https://www.facebook.com/questions/{question-id}>
  • https://www.facebook.com/notes/{username}/{note-url}/{note-id}>

Videos:

  • https://www.facebook.com/{page-name}/videos/{video-id}/>
  • https://www.facebook.com/{username}/videos/{video-id}/>
  • https://www.facebook.com/video.php?id={video-id}>
  • https://www.facebook.com/video.php?v={video-id}>

However, I have no idea how to use regex to check if a given URL matches one of the above URLs.

I've started a regex101 page, but I'm not sure where to go from here:

https://regex101.com/r/M7RTVP/2

2
@Stargateur JavaScript - user7260348
I ask again why do you need a regex? What is your purpose? We could really help you much better if you say it - Stargateur

2 Answers

3
votes

Posts: /^https:\/\/www\.facebook\.com\/(photo(\.php|s)|permalink\.php|media|questions|notes|[^\/]+\/(activity|posts))[\/?].*$/gm

Videos: /^https:\/\/www\.facebook\.com\/([^\/?].+\/)?video(s|\.php)[\/?].*$/gm

0
votes

A simple substring search would be enough for these, but these would work:

Posts: (?:post|activity|photo|media|questions|note|story)

Videos: video