Regular expressions are downright handy for a variety of string processing tasks. They are so handy that they are built straight in to the language in the form of the /regexpgoeshere/ syntax. Well, usually…

The above is true except for one weird case. Consider these simple functions:

function foo(): RegExp
{
	return /^monkey$/;
}
 
var bar:Function = function(): RegExp
{
	return /^monkey$/;
};

They are, of course, almost exactly the same. The former works just fine, but the latter inexplicably blows up at compile time:

Error: Syntax error: expecting identifier before div.
 
				return /^monkey$/;
				       ^

The “div” it is talking about is the first slash in the regular expression. MXMLC is not recognizing regular expressions defined in this way withing anonymous functions. I don’t know why it draws a distinction between anonymous functions and named ones, but it does. Fortunately, the workaround is simple:

var bar:Function = function(): RegExp
{
	return new RegExp("^monkey$");
};

All you have to do is use the RegExp constructor instead. The two are essentially equivalent anyhow, so feel free to use whichever you like wherever you like so long as you always use the RegExp constructor within anonymous functions.