Regular Expressions 101

Community Patterns

youtube iframe embed code src video id and params

0

Regular Expression
ECMAScript (JavaScript)

/
<iframe[\s\w="\/]*src="(?<src>(?:https*:\/\/)?www\.youtube(?:-nocookie)?\.com\/embed\/(?<vid>[-a-zA-Z0-9@:;%_+.~#&=]+)\??(?<params>[-a-zA-Z0-9@:;%_+.~#?&\/=]*))"[^>]*>(?:<\/iframe>)?$
/
gm

Description

Matches full src url and individual video id and params in a YouTube iframe embed tag.

Submitted by Robert Klein Kromhof - 6 years ago