To get the VideoID of a youtube video using Regex you can use the following snippet.

Sample Regex

^(?:http(?:s)?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.[a-zA-Z]{1,3}\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\”‘>]+)

This will match the Vl1tVxfFf1A in https://www.youtube.com/watch?v=Vl1tVxfFf1A.

A more complex regex matching more youtube link variants can be found How to get the Youtube VideoId from Url in C# and VB.NET

One thought on “How to get the VideoID of a youtube video using Regex”

Leave a Reply