SO square bracket RegExp

by pleclech forked from SO escaped RegExp (diff: 12)
♥0 | Line 25 | Modified 2012-09-06 17:02:50 | MIT License
play

ActionScript3 source code

/**
 * Copyright pleclech ( http://wonderfl.net/user/pleclech )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/2MiG
 */

// forked from pleclech's SO escaped RegExp
package {
    import flash.utils.Dictionary;
    import flash.events.Event;
    import flash.utils.setTimeout;
    import com.bit101.components.TextArea
    
    public class FlashTest extends TextArea {
        public function FlashTest() {
            width=400
            height=400
            setTimeout(doTest, 500)                        
        }
         public function doTest():void {
             var testStr:String="This is [an example] of a sentence that has [groups of words] enclosed in [square brackets.]";
             
             var reSentence:RegExp = /[^\[]\[([^\]]+)\]|(\w+)/g;
             var matchObject:Object;
             var result:Array=[];
             while(matchObject=reSentence .exec(testStr))
               result.push(matchObject[1] || matchObject[2]);
             
             trace(result);
        }
        public function trace(...args):void {
            text=text+args.join(", ")+"\n"
        }
    }
}