Community Patterns

Community Library Entry

0

Regular Expression
Created·2021-09-09 16:40
Updated·2021-09-12 16:45
Flavor·Python

r"
^(?:https?:\/\/|\/\/)?(?:(?:www\.|m\.)?youtube(?:-nocookie)?\.com\/(?:(?:vi?|e|embed)\/([\w-]{11})|(?:watch|embed|attribution_link)?\?\S*?(?:(?<=\?v=|&v=)|(?<=\?vi=|&vi=))([\w-]{11}))|youtu\.be\/(?:([\w-]{11})(?!\S*v=)|\S*?(?:&v=|\?v=)([\w-]{11})))(?:[^\w-]\S*)?$
"
gm
Open regex in editor

Description

This regex can match with a valid YouTube link and retrieve the video ID in one of the four capturing groups. Unfortunately, I couldn't manage to use a single capturing group, but there is no difference between all of them.

Submitted by Lyroy TheToad