Search code examples
javascriptregexurlvimeocapture-group

Trying to update a vimeo regex to get the ID from URL which includes "channels/staffpicks"


I have a vimeo regex which works in getting the ID from a standard URL: https://vimeo.com/42100325

I can't get it work when the URL is: https://vimeo.com/channels/staffpicks/142100325

This is what I have at the moment:

var vimeoId = /\/\/(?:www\.)?vimeo.com\/([0-9a-z\-_]+)/i;

Solution

  • Since you are only interested in the part at the end, there is no reason to describe the whole string in the regexp:

    var vimeoId = /([0-9a-z\-_]+)$/i;