Regular Expressions 101

Community Patterns

Capture YouTube Video ID

1

Regular Expression
PCRE (PHP <7.3)

/
(?:youtube(?:-nocookie)?\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})
/
ig

Description

get video id from any version of youtube url

Submitted by Kevin Chappell - 9 years ago