Regular Expressions 101

Community Patterns

Extract just YouTube IDs

0

Regular Expression
PCRE (PHP <7.3)

/
(?<=watch\?v=|\/videos\/|embed\/|youtu.be\/|\/v\/|watch\?v%3D|%2Fvideos%2F|embed%2F|youtu.be%2F|%2Fv%2F)[^#\&\?\n]*
/
ig

Description

You can easily extract YouTube IDs, excluding the paths and parameters.

Submitted by anonymous - 2 years ago