Skip to content

Instantly share code, notes, and snippets.

@amritk
Created January 14, 2019 23:34
Show Gist options
  • Save amritk/e11fccfc75a118cda06a94db2222c5ac to your computer and use it in GitHub Desktop.
Save amritk/e11fccfc75a118cda06a94db2222c5ac to your computer and use it in GitHub Desktop.
A simple regex parser for youtube links
checkForYoutube(body: string) {
const matches = body.match(/\s?((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?\s?/)
if (matches && matches.length > 4) {
this.youtubeUrl = `https://www.youtube.com/embed/${matches[5]}`
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment