Skip to content

Instantly share code, notes, and snippets.

@jonathantneal
Last active March 24, 2021 10:35
Show Gist options
  • Save jonathantneal/6802513 to your computer and use it in GitHub Desktop.
Save jonathantneal/6802513 to your computer and use it in GitHub Desktop.
Parsing Social Media URLs

Parsing Social URLs

Match a variety of social media urls, detect their medium, and collect their single-most important ID.

{
	dailymotion: /https?:\/\/(?:www\.)?dailymotion\.com\/(swf|video)\/([^\/?&]+)/,
	googlemaps: /(^https?\:\/\/maps\.google\.com.+)/,
	googleplus: /https?:\/\/(?:plus\.google\.com|gplus\.to)\/([^\/?&]+)/,
	flickr: /https?:\/\/(?:www\.)?flickr\.com\/(?:people|photos)\/(\d+@N\d+)/,
	instagram: /https?:\/\/(?:www\.)?instagram\.com\/p\/([^\/?&]+)/,
	linkedinUser: /https?:\/\/(?:www\.)?linkedin\.com\/(?:in|pub)\/([^\/?&]+)/,
	tumblr: /^(?:https?:\/\/)?([\.]+)\.tumblr\.com/,
	twitterUser: /(?:^@|https?:\/\/(?:www\.)?twitter\.com\/)([^\/?&]+)/,
	vimeo: /https?:\/\/(?:www\.)?vimeo\.com\/(?:channels\/.+?\/|groups\/.+?\/videos\/)([^\/?&]+)/,
	vine: /https?:\/\/(?:www\.)?vine\/.co\/v\/([^\/?&]+)/,
	youtube: /https?:\/\/(?:(?:www\.)youtube\.com|youtu\.be)\/(?:watch.*[?&]v=|v\/|embed\/|apiplayer.*[?&]video_id=)?([a-zA-Z0-9_-]{11})/,
	youtubeUser: /https?:\/\/(?:www\.)?youtube.com\/(user\/)?([^\/?&]+)/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment