AS3 Regular expression
Any of you gone through this task? Please tell me a solution.
I have to extract video id alone from youtube url : http://www.youtube.com/watch?v=Ls8ppLu72NQ&feature=popular
From this i need only Ls8ppLu72NQ How can i extract it. I know i can use string replace but is there a way to
extract it easily with regex.Url can be all these forma开发者_如何学Gots
http://www.youtube.com/watch?v=Ls8ppLu72NQ&feature=popular
http://www.youtube.com/watch?v=Ls8ppLu72NQ
http://www.youtube.com/watch/Ls8ppLu72NQ
Try this regex:
watch(?:\/|(?:\?|.*&)v=)(\w+)
The result will be in the 1st capture group.
Demo: http://rubular.com/r/7J9FSgwBMf
Thanks a lot @Aillyn
Its worked for me.
I made it in the following way **
var myPattern:RegExp = /watch(?:\/|(?:\?|.*&)v=)(\w+)/ig;
var str:String = "http://www.youtube.com/watch?&vx=123&v=Ls8ppLu72NT";
var result:Object = myPattern.exec(str);
trace(result[1]);
**
精彩评论