More on Regular Expressions!

| Comments

i was trying to understand what’s happening behind scenes in the Log Class in Flex Framework if you digg a little bit in their Classes you’ll find something like this

                public function debug(msg:String, ... rest):void
            if (hasEventListener(LogEvent.LOG))
                // replace all of the parameters in the msg string
                for (var i:int = 0; i < rest.length; i++)
                    msg = msg.replace(new RegExp("\{"+i+"\}", "g"), rest[i]);

                dispatchEvent(new LogEvent(msg, LogEventLevel.DEBUG));

so what’s means msg = msg.replace(new RegExp(“{“+i+”}”, “g”), rest[i]); ?????? that means whenever you find “{0}” …. “{n}” replace it by the string rest[0] … rest[n]

so you can use

Log.debug("the song says {0} little {1} little {2} little-endians" , 'zero','one','two');
//outputs:  the song says zero little one little two little-endians

for me is so hard to read a Regular Expressions especially because i always forget all means of meta characters and meta secquencies hehehe