How to match youtube links?

The following regex will match youtube urls with the domains youtube.com and youtu.be. It will capture the video id in capture group 1.

Example: https://www.youtube.com/watch?v=RBpsFKdqaHw

Regex: (?:https?:\/\/)?(?:youtu\.be\/|(?:www\.|m\.)?youtube\.com\/(?:watch|v|embed)(?:\.php)?(?:\?.*v=|\/))([a-zA-Z0-9\-_]+)



×

Subscribe

The latest tutorials sent straight to your inbox.