Skip to content

Instantly share code, notes, and snippets.

@JonasAlfredsson
Created August 15, 2019 21:23
Show Gist options
  • Save JonasAlfredsson/dcf99ae8f70e385c70d404521d7c4655 to your computer and use it in GitHub Desktop.
Save JonasAlfredsson/dcf99ae8f70e385c70d404521d7c4655 to your computer and use it in GitHub Desktop.
YouTube URL regex for bash.
if [[ $URL =~ ^(https?://)?(www.)?(youtu.be/|youtube.com/(embed/|v/|watch\?v=|watch\?.+&v=|playlist\?list=))([[:alnum:]|_|-]{11})($|&(.+)?) ]]; then
# This seems to be a link from YouTube with some video ID attached.
else
# This was not recognized as a YouTube link.
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment