Regular Facebook URL update
I am trying to validate facebook video url using regex.
this is an example of Valid fb video url:
https://www.facebook.com/video.php?v=100000000000000 (VALID)
this is an example url of a valid fb video with username: https://www.facebook.com/ {username} / video / 100000000000000
note: {username} can contain any string. example: https://www.facebook.com/username1/videos/100000000000000 (VALID) https://www.facebook.com/username2/videos/100000000000000 (VALID)
But my reqex is still wrong if I check the url of the video snippet with the username.
This is my regex:
^http(s)?://(www\.)?facebook.([a-z]+)/(?!(?:video\.php\?v=\d+|usernameFB/videos/\d+)).*$
You can run it: https://regex101.com/r/dF5iP1/6
source to share
Neither of the two existing ones worked for me, not to say they have few visible cases.
So here's my REGEX suggestion :
^(?:(?:https?:)?\/\/)?(?:www\.)?facebook\.com\/[a-z\.]+\/videos\/(?:[a-z0-9\.]+\/)?([0-9]+)\/?(?:\?.*)?$
I ignored video.php
, I think he's old enough to safely ignore him.
Matches:
https://www.facebook.com/aguardos.nocturnos/videos/vb.1614866072064590/1828228624061666/?type=2&theater https://www.facebook.com/aguardos.nocturnos/videos/vb.1614866072064590/1828228624061666?type=2&theater 2 & theater https://www.facebook.com/aguardos.nocturnos/videos/1828228624061666/ https://www.facebook.com/latavernadelssomnis/videos/1609038972452561/?hc_ref=NEWSFEED //www.facebook.com/aguardos.nocturnos / videos / 1828228624061666 / https://facebook.com/aguardos.nocturnos/videos/1828228624061666/ http://www.facebook.com/aguardos.nocturnos/videos/1828228624061666/ www.facebook.com/aguardos.nocturnos/videos / 18282286240612666 / facebook.com/aguardos.nocturnos/videos/18282286240612666/ https://www.facebook.com/aguardos.nocturnos/videos/1828228624061666
I don't own or watch any of the videos. I just picked random ones that were in my facebook post.
Groups
- Video ID.
Test
You can easily test it yourself with Regex101
source to share