Created
January 14, 2019 23:34
-
-
Save amritk/e11fccfc75a118cda06a94db2222c5ac to your computer and use it in GitHub Desktop.
A simple regex parser for youtube links
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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