Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
^https?:\/\/(?:(?:(?:www\.)?youtu(?:(?:be\.(?:com|nl|it|co\.nz|com\.br|de|es|ru))|(?:be-nocookie\.com))\/(?:(?:watch\?v=)|(?:v\/)|(?:embed\/)))|(?:youtu\.be\/))(?<video_id>[a-zA-Z0-9\-_]{11})(?:[a-zA-Z0-9\-_\?=&%\.]+)?$
/
gm

Description

Only validates (and extracts) a correct YouTube video ID

Submitted by Wiliam Castilhos, Ramon Barros - 5 years ago