User Guide

Regular expression syntax 299
Flags and properties
The following table lists the five flags that you can set for regular expressions. Each flag can be
accessed as a property of the regular expression object.
Note that these properties are read-only. You can set the flags (
g, i, m, s, x) when you set a
regular expression variable, as follows:
var re:RegExp = /abc/gimsx;
However, you cannot directly set the named properties. For instance, the following code
results in an error:
var re:RegExp = /abc/;
re.global = true; // This generates an error.
By default, unless you specify them in the regular expression declaration, the flags are not set,
and the corresponding properties are also set to
false.
Additionally, there are two other properties of a regular expression:
The lastIndex property specifies the index position in the string to use for the next call
to the
exec() or test() method of a regular expression.
The source property specifies the string that defines the pattern portion of the regular
expression.
The g (global) flag
When the g (global) flag is not included, a regular expression matches no more than one
match. For example, with the
g flag not included in the regular expression, the
String.match() method returns only one matching substring:
var str:String = "she sells seashells by the seashore.";
var pattern:RegExp = /sh\w*/;
trace(str.match(pattern)) // output: she
Flag Property Description
g global
Matches more than one match.
i ignoreCase
Case-insensitive matching. Applies to the AZ and az characters,
but not to extended characters such as
É and é.
m multiline
With this flag set, $ and ^ can match the beginning of a line and end
of a line, respectively.
s dotall
With this flag set, . (dot) can match the newline character (\n).
x extended
Allows extended regular expressions. You can type spaces in the
regular expression, which are ignored as part of the pattern. This lets
you type regular expression code more legibly.