Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
^(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/watch\?v=([a-zA-Z0-9_]+)|youtu\.be\/([a-zA-Z\d_]+))(?:&.*)?$
/
gm

Description

Matches Youtube video links

Matches the video id as (group 1) for regular youtube links.

Matches the video id as (group 2) for shared Youtube links.

Submitted by anonymous - 5 years ago