Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package;
- import flash.display.MovieClip;
- import flash.Lib;
- class Main extends MovieClip
- {
- public function new()
- {
- super();
- test0();
- //test1();
- }
- function test0()
- {
- /* AS3:
- var regexp:RegExp = /(\w*)sh(\w*)/ig;
- var str:String = "She sells seashells by the seashore";
- var result:Object = regexp.exec(str);
- while (result != null)
- {
- trace ( result.index, "\t", result);
- result = regexp.exec(str);
- }
- This code results in the following output:
- 0 She,,e
- 10 seashells,sea,ells
- 27 seashore,sea,ore
- */
- var reg : EReg = ~/(\w*)sh(\w*)/ig;
- var str:String = "She sells seashells by the seashore";
- var result = reg.match(str);
- while(result)
- {
- trace([reg.matchedPos().pos, reg.matchedPos().len, reg.matched(0), reg.matched(1), reg.matched(2)]);
- result = reg.match(str);
- }
- }
- function test1()
- {
- var str ='[[11,22], [33,44]]';
- //var reg = new EReg('\\[([0-9]+),([0-9]+)\\]', "");
- var reg : EReg = ~/\[([0-9]+),([0-9]+)\]/;
- while(reg.match(str))
- {
- var i = reg.matchedPos().pos+reg.matchedPos().len;
- str = str.substr(i,str.length-i);
- trace(reg.matched(1));//11
- trace(reg.matched(2));//22
- }
- }
- public static function main()
- {
- flash.Lib.current.addChild(new Main());
- }
- }
- /*
- Main
- -main Main
- -swf9 main.swf
- */
Advertisement
Add Comment
Please, Sign In to add comment