How to match UUIDs?
Matching unique identifiers
Everything you need to know about writing regular expressions for PHP.
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\-_]+)