Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

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

Comments

  • www.regular-expressions.info
  • edited March 2007
    Got it /(?<=v(=|\/))([A-Za-z0-9-]+)/g and /(?<=docid(=|\/))([A-Za-z0-9-]+)/g and this to catch both /(?<=(v|[docid])(=|\/))([A-Za-z0-9-]+)/g Is it a bad idea to catch both google video and youtube with one expression
  • Provided they work, I don't see why not...
  • looks like it only works in webkit nightly not firefox. so back to square one
  • this works on o9, ff2 and ie7:
    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;
    }
This discussion has been closed.