Solved

Extracting ID from Vimeo URL using JavaScript

Posted on 2014-01-11
4
899 Views
Last Modified: 2014-01-11
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
Comment
Question by:ivanblue
  • 2
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
Comment Utility
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
 
LVL 1

Author Comment

by:ivanblue
Comment Utility
It works perfectly! Can you please explain how this works?
Thanks so much!
0
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
Did you check the link provided?
0
 
LVL 1

Author Comment

by:ivanblue
Comment Utility
Yes, now I did. Thanks leakim971!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now