13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Using regular expressions<br />

Characters, metacharacters, and metasequ<strong>en</strong>ces<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

The simplest regular expression is one that matches a sequ<strong>en</strong>ce of characters, as in the following example:<br />

var pattern:RegExp = /hello/;<br />

However, the following characters, known as metacharacters, have special meanings in regular expressions:<br />

^ $ \ . * + ? ( ) [ ] { } |<br />

For example, the following regular expression matches the letter A followed by zero or more instances of the letter B<br />

(the asterisk metacharacter indicates this repetition), followed by the letter C:<br />

/AB*C/<br />

To include a metacharacter without its special meaning in a regular expression pattern, you must use the backslash (\)<br />

escape character. For example, the following regular expression matches the letter A followed by the letter B, followed<br />

by an asterisk, followed by the letter C:<br />

var pattern:RegExp = /AB\*C/;<br />

A metasequ<strong>en</strong>ce, like a metacharacter, has special meaning in a regular expression. A metasequ<strong>en</strong>ce is made up of more<br />

than one character. The following sections provide details on using metacharacters and metasequ<strong>en</strong>ces.<br />

About metacharacters<br />

The following table summarizes the metacharacters that you can use in regular expressions:<br />

Metacharacter Description<br />

^ (caret) Matches at the start of the string. With the m (multiline) flag set, the caret matches the start of a line as<br />

well (see “Flags and properties” on page 87). Note that wh<strong>en</strong> used at the start of a character class, the caret<br />

indicates negation, not the start of a string. For more information, see “Character classes” on page 81.<br />

$(dollar sign) Matches at the <strong>en</strong>d of the string. With the m (multiline) flag set, $ matches the position before a newline<br />

(\n) character as well. For more information, see “Flags and properties” on page 87.<br />

\ (backslash) Escapes the special metacharacter meaning of special characters.<br />

. (dot) Matches any single character.<br />

Also, use the backslash character if you want to use a forward slash character in a regular expression literal,<br />

as in /1\/2/ (to match the character 1, followed by the forward slash character, followed by the character<br />

2).<br />

A dot matches a newline character (\n) only if the s (dotall) flag is set. For more information, see “Flags<br />

and properties” on page 87.<br />

* (star) Matches the previous item repeated zero or more times.<br />

For more information, see “Quantifiers” on page 82.<br />

+ (plus) Matches the previous item repeated one or more times.<br />

For more information, see “Quantifiers” on page 82.<br />

? (question mark) Matches the previous item repeated zero times or one time.<br />

For more information, see “Quantifiers” on page 82.<br />

Last updated 6/6/2012<br />

79

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!