Created
March 31, 2023 11:35
-
-
Save devbyray/8f1c9b0aaa552c53b8cd69fcca4011f2 to your computer and use it in GitHub Desktop.
If Youtube URL JavaScript/TypeScript Regex
This file contains hidden or 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
| function isYouTubeUrl(url: string): boolean { | |
| const regex = /^(?:(?:https?:)?\/\/)?(?:www\.)?(?:m\.)?youtu(?:\.be\/|be\.com\/watch\?v=|be\.com\/embed\/|be\.com\/v\/|be\.com\/playlist\?list=|be\.com\/.+\/.+\/.+\/.+\/.+\/.)([A-Za-z0-9_-]{11})(?:\S+)?/; | |
| return regex.test(url); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment