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.
LVL 1
ivanblueAsked:
Who is Participating?
 
leakim971Connect With a Mentor PluritechnicianCommented:
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
All Courses

From novice to tech pro — start learning today.