最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript - Regex Vimeo ID - Stack Overflow

programmeradmin3浏览0评论

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

/\/\/(?:www\.|player\.)?vimeo\/(?: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.

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

/\/\/(?:www\.|player\.)?vimeo.\/(?: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.

Share Improve this question asked Dec 18, 2016 at 12:45 freakyfreaky 1,0103 gold badges18 silver badges45 bronze badges 6
  • Since you are using the regex, consider JSLint is wrong. – Jongware Commented Dec 18, 2016 at 12:51
  • 1 Hum... I think I found my mistake, I have a | in middle of nowhere and I just need to replace "video\/|)(\d+)" by "video\/)?(\d+)". It works fine and it's valid. – freaky Commented Dec 18, 2016 at 12:53
  • Ah - but so was your original regex! An empty or, as in (a|) is valid; it will match an a or nothing. So JSLint is wrong. (Perhaps that would be a good answer. Using JSLint is an excellent practice, but one need to be aware it's still only written by humans.) – Jongware Commented Dec 18, 2016 at 12:56
  • And does my second attempt will have the same behaviour as an empty or? I'm really not an expert in regex.... – freaky Commented Dec 18, 2016 at 12:57
  • 1 Ok. Thank you for your help. I will test all the possibilities with regex101. and check what is the best solution whatever if JSLint do a warning... – freaky Commented Dec 18, 2016 at 13:02
 |  Show 1 more ment

1 Answer 1

Reset to default 8

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

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

发布评论

评论列表(0)

  1. 暂无评论