Regular Expressions 101

Community Patterns

Youtube ID match

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 - 10 years ago