Search code examples
javascriptregexvimeo

Javascript - Regex Vimeo ID


I'm using this regex to get the Vimeo video ID from an url:

/\/\/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/(?:[^\/]*)\/videos\/|album\/(?:\d+)\/video\/|video\/|)(\d+)(?:[a-zA-Z0-9_\-]+)?/i

However, this regex seems to have some typo and issue when I try to valide it thanks to JSLint for example:

Expected a regexp factor and instead saw ')'.

I can't find where the issue is exactly.


Solution

  • JSLint is complaining about the pipe on video\/|, it's safe to ignore this error.

    var subject = "https://vimeo.com/195940605";
    var result = subject.match(/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/(?:[^\/]*)\/videos\/|album\/(?:\d+)\/video\/|video\/|)(\d+)(?:[a-zA-Z0-9_\-]+)?/i);
    document.write(result[0]);