Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1208
  • Last Modified:

Extracting ID from Vimeo URL using JavaScript

Hello, I'm using this code to extract the ID from a Vimeo URL:

vimeo_id = message.split(/video\/|http:\/\/vimeo\.com\//)[1].split(/[?&]/)[0];

Open in new window

But this code doesn't work when there's https instead of http. How can I make it work with https too? I prefer to keep the split instead of using a regexp if possible.

And how does this code work? Can you explain it?

Thanks.
0
ivanblue
Asked:
ivanblue
  • 2
  • 2
1 Solution
 
leakim971PluritechnicianCommented:
Add << s? >>  after http

http://www.regular-expressions.info/optional.html

vimeo_id = message.split(/video\/|https?:\/\/vimeo\.com\//)[1].split(/[?&]/)[0];

Open in new window

0
 
ivanblueAuthor Commented:
It works perfectly! Can you please explain how this works?
Thanks so much!
0
 
leakim971PluritechnicianCommented:
Did you check the link provided?
0
 
ivanblueAuthor Commented:
Yes, now I did. Thanks leakim971!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now