RegularExpression help
ok guys, need help
I want to extract Youtube video ID
It comes in 2 possible variations. in the example below the video id is ibvwUyeKe8c
http://www.youtube.com/watch?v=ibvwUyeKe8c
http://www.youtube.com/v/ibvwUyeKe8c
Now i need a regular expression in JAVASCRIPT, that will extract the video id from the above strings
So i'm looking for what comes after v= and v/ and before & or eol
Good luck
avcourse i will extend it to Google video as well
http://video.google.com/googleplayer.swf?docId=8196749249677852682&hl=en
http://video.google.com/videoplay?docid=8196749249677852682
I want to extract Youtube video ID
It comes in 2 possible variations. in the example below the video id is ibvwUyeKe8c
http://www.youtube.com/watch?v=ibvwUyeKe8chttp://www.youtube.com/v/ibvwUyeKe8c
Now i need a regular expression in JAVASCRIPT, that will extract the video id from the above strings
So i'm looking for what comes after v= and v/ and before & or eol
Good luck

avcourse i will extend it to Google video as well
http://video.google.com/googleplayer.swf?docId=8196749249677852682&hl=en
http://video.google.com/videoplay?docid=8196749249677852682
0
This discussion has been closed.
Comments
function find_videos(str) { var t, reg, vids, i, type; reg = /\/(watch\?v=|v\/|(googleplayer.swf|videoplay)\?docid=)([A-Za-z0-9_\-]+)/igm; vids = Array(); RegExp.lastIndex = i = 0; while( (t = reg.exec(str)) != null ) { if(t[2] != undefined) type = 'googlevideo'; else type = 'youtube'; vids[i++] = { 'type' : type, 'id' : t[3] }; } return vids; }