Last active
September 4, 2017 18:20
-
-
Save oburt/0e7d7a5ab8c6e54c24ff to your computer and use it in GitHub Desktop.
Regex for embeds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var re = /(?:http:|https:|)(?:\/\/|)(?:gfycat\.com\/(?:\w*\/)*)(\w+$)/gi; | |
var matches = re.exec( 'http://gfycat.com/GroundedMinorAcornbarnacle' ); | |
matches = [ | |
"http://gfycat.com/GroundedMinorAcornbarnacle", | |
"GroundedMinorAcornbarnacle" | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var re = /(?:http:|https:|)(?:\/\/|)(?:instagr\.am|instagram\.com)\/p\/([\w-]+)\//gi; | |
var matches = re.exec( 'http://instagram.com/p/aq2aANLEd-/' ); | |
matches = [ | |
"http://instagram.com/p/aq2aANLEd-/", | |
"aq2aANLEd-" | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var re = /(?:http:|https:|)(?:\/\/|)(?:www\.|)(?:scribd\.com)\/\w+\/([\d-]+)\/[\w;:@#%=+\/\$_.-]*/gi; | |
var matches = re.exec( 'http://www.scribd.com/doc/134766598/Master-s-Thesis-Analyzing-USA-Ultimate-Algorithm' ); | |
matches = [ | |
"http://www.scribd.com/doc/134766598/Master-s-Thesis-Analyzing-USA-Ultimate-Algorithm", | |
"134766598" | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var re = /(?:http:|https:|)(?:\/\/|)(?:storify\.com\/)(\w*)\/([\w-]+$)/gi; | |
var matches = re.exec( 'https://storify.com/Ulti_world/tweets-about-espnu-s-college-champs-broadcast' ); | |
matches = [ | |
"https://storify.com/Ulti_world/tweets-about-espnu-s-college-champs-broadcast", | |
"Ulti_world", | |
"tweets-about-espnu-s-college-champs-broadcast" | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var re = /(?:http:|https:|)(?:\/\/|)(?:twitter\.com\/(\w*)\/(?:(status)es\/|\w*\/)*)(\d+$)/gi; | |
var matches = re.exec( 'https://twitter.com/BarackObama/statuses/266031293945503744' ); | |
matches = [ | |
"https://twitter.com/BarackObama/statuses/266031293945503744", | |
"BarackObama", | |
"status", | |
"266031293945503744" | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var re = /(?:http:|https:|)(?:\/\/|)(?:(?:player\.)?vimeo\.com\/(?:\w*\/)*)(\d+)/gi; | |
var matches = re.exec( 'http://vimeo.com/60209852' ); | |
matches = [ | |
"http://vimeo.com/60209852", | |
"60209852" | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Based on LinuxPanda's regex, /t=/ modified so it's optional and works on all youtube links | |
// http://linuxpanda.wordpress.com/2013/07/24/ultimate-best-regex-pattern-to-get-grab-parse-youtube-video-id-from-any-youtube-link-url/ | |
var re = /(?:http:|https:|)(?:\/\/|)(?:www.|)(?:youtu\.be\/|youtube\.com(?:\/embed\/|\/v\/|\/watch\?v=|\/ytscreeningroom\?v=|\/feeds\/api\/videos\/|\/user\S*[^\w\-\s]|\S*[^\w\-\s]))([\w\-]{11})(?:[?&](?:t=((\d+h)?(\d+m)?(\d+s)?))|[?&][\w;:@#%=+\/\$_.-]*)*/gi; | |
var matchesWithoutTime = re.exec( 'youtu.be/yVpbFMhOAwE' ); | |
matchesWithoutTime = [ | |
"youtu.be/yVpbFMhOAwE", | |
"yVpbFMhOAwE", | |
undefined, | |
undefined, | |
undefined, | |
undefined | |
]; | |
var matchesWithTime = re.exec( 'http://www.youtube.com/watch?v=yVpbFMhOAwE&feature=g-vrec&t=1m30s' ); | |
matchesWithTime = [ | |
"http://www.youtube.com/watch?v=yVpbFMhOAwE&feature=g-vrec&t=1m30s", | |
"yVpbFMhOAwE", | |
"1m30s", | |
undefined, | |
"1m", | |
"30s" | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment