Skip to content

Instantly share code, notes, and snippets.

@Ragnarokkr
Last active August 29, 2015 14:25
Show Gist options
  • Select an option

  • Save Ragnarokkr/12428dc2e23bff2a8fb1 to your computer and use it in GitHub Desktop.

Select an option

Save Ragnarokkr/12428dc2e23bff2a8fb1 to your computer and use it in GitHub Desktop.
Youtube/Vimeo URL matching patterns.

This pattern aims to match (testing only) all Youtube's and Vimeo's URL variants.

^(?:https?:)?(?:(?:\/\/(?:(?:www\.)?(?:youtube\.com)|youtu\.be)\/.*?(?:watch\?v=|embed\/)?)?(?:[\w-]{11}(?![\w-]))|(?:\/\/vimeo\.com\/)?[\d]{9}(?![\w])).*$

This pattern matches Youtube only URLs:

^((https?:)?(?:(?:\/\/((?:www\.)?youtube\.com|youtu\.be)\/.*?(?:watch\?v=|embed\/)?)))?([\w-]{11})

  • group 2: stores the protocol
  • group 3: stores the domain
  • group 4: stores the video ID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment