Topic on Extension talk:Regex Fun

Parse video ID from youtube Link

2
Nischayn22 (talkcontribs)

I am trying to get the video ID from a youtube link using this extension but have failed. If anyone has done this please share.

Danwe (talkcontribs)

Have a look at this StackOverflow question. As you can see there are various answers and comments so I just picked one (not necessarily the best or most suitable for you) of the described solutions there. Keep in mind that there is a chance that this might not work with all future youtube IDs if Google changes the format.

This should give you an empty string if no valid youtube url is given and the video ID if a valid url is given (not tested):

{{#regex: URL HERE | /^.*(?:youtu.be\/{{!}v\/{{!}e\/{{!}u\/\w+\/{{!}embed\/{{!}v=)([^#\&\?]*).*/ir | $1 }}

Reply to "Parse video ID from youtube Link"