Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 300

Programming actionscript 3.0
Table of Contents

Advertisement

When the
flag is set, the
g
var str:String = "she sells seashells by the seashore.";
var pattern:RegExp = /sh\w*/g;
// The same pattern, but this time the g flag IS set.
trace(str.match(pattern)); // output: she,shells,shore
The i (ignoreCase) flag
By default, regular expression matches are case-sensitive. When you set the
flag, case sensitivity is ignored. For example, the lowercase
match the uppercase letter
var str:String = "She sells seashells by the seashore.";
trace(str.search(/sh/)); // output: 13 -- Not the first character
With the
flag set, however, the regular expression does match the capital letter
i
var str:String = "She sells seashells by the seashore.";
trace(str.search(/sh/i)); // output: 0
The
flag ignores case sensitivity only for the
i
characters such as
and
É
The m (multiline) flag
If the
(
) flag is not set, the
m
multiline
matches the end of the string. If the
and end of a line, respectively. Consider the following string, which includes a newline
character:
var str:String = "Test\n";
str += "Multiline";
trace(str.match(/^\w*/g)); // Match a word at the beginning of the string.
Even though the
(
g
global
only one substring, since there is only one match for the
output is:
Test
Here is the same code with the
var str:String = "Test\n";
str += "Multiline";
trace(str.match(/^\w*/gm)); // Match a word at the beginning of lines.
This time, the output includes the words at the beginning of both lines:
Test,Multiline
300
Using Regular Expressions
method returns multiple matches, as follows:
Sting.match()
, the first character of the string:
S
.
é
matches the beginning of the string and the
^
flag is set, these characters match the beginning of a line
m
) flag is set in the regular expression, the
flag set:
m
in the regular expression does not
s
and
characters, but not for extended
A
Z
a
z
—the beginning of the string. The
^
(
i
ignoreCase
:
S
$
method matches
match()
)

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents