Regular Expressions 101

Community Patterns

Community Library Entry

9

Regular Expression
PCRE (PHP <7.3)

/
(?<=\d\/|\.be\/|v[=\/])([\w\-]{11,})|^([\w\-]{11})$
/
gim

Description

This regex will match any Youtube video ID thrown at it and return one capturing group containing the ID.

Submitted by Jacob Overgaard - 11 years ago