Skip to content

Instantly share code, notes, and snippets.

@tobiaswx
Last active May 21, 2020 20:40
Show Gist options
  • Save tobiaswx/3c6707911ea716860786728d31f8e3e5 to your computer and use it in GitHub Desktop.
Save tobiaswx/3c6707911ea716860786728d31f8e3e5 to your computer and use it in GitHub Desktop.
Regex | Regular Expression to identify YouTube-URLs with video-id match
https://regex101.com/r/l0m7yh/3
Regex: ^(https?\:\/\/)?(www\.)?(youtube\.com|youtu\.?be)(\/)?(embed\/)?(watch\?v=|\?v=)?(?<video_id>.*)$
Group 7 / 'video_id' includes the video-id
Testes with examples like:
https://www.youtube.com/watch?v=osz5tVY97dQ
https://youtube.com/watch?v=osz5tVY97dQ
https://youtube.com/osz5tVY97dQ
youtube.com/watch?v=osz5tVY97dQ
https://www.youtu.be/watch?v=osz5tVY97dQ
https://youtu.be/watch?v=osz5tVY97dQ
https://youtu.be/?v=osz5tVY97dQ
https://youtu.be/osz5tVY97dQ
youtu.be/osz5tVY97dQ
https://www.youtube.com/embed/osz5tVY97dQ
@tobiaswx
Copy link
Author

Update 21.05.2020:

  • Support for embed-URL's
  • Group is now named (video_id)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment