Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
ECMAScript (JavaScript)

/
(?:^$|^(?:https?:)?(?:\/\/)?(?:youtu\.be\/|(?:www\.|m\.)?youtube\.com\/(?:watch|v|embed)(?:\.php)?(?:\?.*v=|\/))([a-zA-Z0-9\_\-]{7,15})(?:[\?&][a-zA-Z0-9\_\-]+=[a-zA-Z0-9\_\-]+)*$)
/
mg

Description

Matches correct youtube video urls and empty strings.

Submitted by xeon927 on stackoverflow - 3 years ago