Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
(?:[?&]vi?=|\/embed\/|\/\d\d?\/|\/vi?\/|https?:\/\/(?:www\.)?youtu\.be\/)([A-Za-z0-9_\-]{11})
/
g

Description

This straight forward regex extracts the Video ID from many different YouTube URL types.

Submitted by Teocci - 7 years ago