jan_flanders

Untitled

May 3rd, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package;
  2. import flash.display.MovieClip;
  3. import flash.Lib;
  4.  
  5. class Main extends MovieClip
  6. {
  7.     public function new()
  8.     {
  9.         super();
  10.         test0();
  11.         //test1();
  12.     }
  13.     function test0()
  14.     {
  15.         /* AS3:
  16.         var regexp:RegExp = /(\w*)sh(\w*)/ig;  
  17.         var str:String = "She sells seashells by the seashore";
  18.         var result:Object = regexp.exec(str);
  19.         while (result != null)
  20.         {
  21.              trace ( result.index, "\t", result);
  22.              result = regexp.exec(str);
  23.         }
  24.         This code results in the following output:
  25.  
  26.  
  27.             0      She,,e
  28.             10     seashells,sea,ells
  29.             27     seashore,sea,ore
  30.          
  31.         */
  32.         var reg : EReg = ~/(\w*)sh(\w*)/ig;
  33.         var str:String = "She sells seashells by the seashore";
  34.         var result = reg.match(str);
  35.         while(result)
  36.         {
  37.             trace([reg.matchedPos().pos, reg.matchedPos().len, reg.matched(0), reg.matched(1), reg.matched(2)]);
  38.             result = reg.match(str);
  39.         }
  40.     }
  41.     function test1()
  42.     {
  43.         var str ='[[11,22], [33,44]]';
  44.         //var reg = new EReg('\\[([0-9]+),([0-9]+)\\]', "");
  45.         var reg : EReg = ~/\[([0-9]+),([0-9]+)\]/;
  46.  
  47.         while(reg.match(str))
  48.         {
  49.             var i = reg.matchedPos().pos+reg.matchedPos().len;
  50.             str = str.substr(i,str.length-i);
  51.             trace(reg.matched(1));//11
  52.             trace(reg.matched(2));//22
  53.         }
  54.     }
  55.     public static function main()
  56.     {
  57.         flash.Lib.current.addChild(new Main());
  58.     }
  59. }
  60. /*
  61. Main
  62. -main Main
  63. -swf9 main.swf
  64. */
Advertisement
Add Comment
Please, Sign In to add comment