Saturday, July 9, 2011

ActionScript Regular Expression Tester

Here is a little tool I created using Adobe Flex to match a string against a regular expression. It tries to mimic the functionality of matches() function in .NET Regular Expression to return an array of matches. I have another idea to improve this, so I am back to work!

Here is matches function that I used. The application is after the code.

public static function getMatches(expression:RegExp, stringToMatch:String):Array
        {
            if (!expression.global)
            {
                throw new Error("expression.global is not true!");
            }
            
            var matches:Array = new Array();
            
            var allMatchesFound:Boolean = false;
            
            while (allMatchesFound == false)
            {
                var match:String = expression.exec(stringToMatch);
                
                if(match != null)
                {
                    matches.push(match);
                }
                else
                {
                    allMatchesFound = true;
                }
            }
            
            return matches;
        }



No comments:

Post a Comment