Javascript Code Regex YouTube Video URL

How to find YouTube Video URLs in a String in Javascript Using Regex /(?:https?)\:\/\/(?:(www.)?)youtube.com\/watch\?v=[a-zA-Z0-9-_\.]{7,12}/gi

Home Short:

Searching in JavaScript for a youtube video url is not too difficult with regex using the regex syntax below. This will match youtube urls as both https://www.youtube.com/watch?v=LyfI8sfwwer2 and https://youtu.be/puSK4XFHr8I?si=Yy0IQmlhE0r4Ns.

S
H
A
R
E