JimmyBanks
JimmyBanks

Reputation: 4718

Regular expression to determine URL video ID

I would like to use a regular expression to determine the video ID of NHL.com videos.

Example urls are the following:

1. http://video.nhl.com/videocenter/console?id=789500&catid=35
2. http://video.senators.nhl.com/videocenter/console?id=790130&catid=1141
3. http://video.nhl.com/videocenter/?id=2013020884-605-h

From these examples, the values I would need are as follows:

1. 789500
2. 790130
3. 2013020884-605-h

I would like to use the match() function to obtain the ID following ?id=, the ID's can include characters that are alphanumeric, underscore, and dash.

Upvotes: 0

Views: 65

Answers (1)

anubhava
anubhava

Reputation: 785896

You can use:

/\?id=([^&]+)/gi

i.e.

var re = /[?&]id=([^&#]+)/i;

And use matched group #1:

var m = str.match(re);
var id = m[1];

RegEx Demo

Upvotes: 4

Related Questions