I need help with RegExp in AS3.
I have a simple template:
patternYouTube = new RegExp ( "v(?:\/|=)([A-Z0-9_-]+)", "gi" );
This template searches for youTube video.
For instance:
var tmpUrl : String; var result : Object; var toto : Array = new Array(); toto = ["http://www.youtube.com/v/J-vCxmjCm-8&autoplay=1", "http://www.youtube.com/v/xFTRnE1WBmU&autoplay=1"]; var i : uint; for ( i = 0 ; i < toto.length ; i++) { tmpUrl = toto[i]; result = patternYouTube.exec ( tmpUrl ); if ( result.length != 0 && result != null ) { trace(result); } }
When I == 0, it works fine. Flash brings me back: v/J-vCxmjCm-8,J-vCxmjCm-8
When I == 1, it fails. Flash brings me back: null
When I return two lines in my array, such as:
toto = [ http://www.youtube.com/v/xFTRnE1WBmU&autoplay=1, http://www.youtube.com/v/J-vCxmjCm-8&autoplay=1 ];
When I == 0, it works fine: Flash returns me: xFTRnE1WBmU
When I == 1, it fails: Flash returns me: null
Do you have any idea about the problem in the loop?
source share