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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

Using regular expressions<br />

Important concepts and terms<br />

The following refer<strong>en</strong>ce list contains important terms that are relevant to this feature:<br />

Escape character A character indicating that the character that follows should be treated as a metacharacter rather<br />

than a literal character. In regular expression syntax, the backslash character (\) is the escape character, so a backslash<br />

followed by another character is a special code rather than just the character itself.<br />

Flag A character that specifies some option about how the regular expression pattern should be used, such as whether<br />

to distinguish betwe<strong>en</strong> uppercase and lowercase characters.<br />

Metacharacter A character that has special meaning in a regular expression pattern, as opposed to literally<br />

repres<strong>en</strong>ting that character in the pattern.<br />

Quantifier A character (or several characters) indicating how many times a part of the pattern should repeat. For<br />

example, a quantifier would be used to designate that a United States postal code should contain five or nine numbers.<br />

Regular expression A program statem<strong>en</strong>t defining a pattern of characters that can be used to confirm whether other<br />

strings match that pattern or to replace portions of a string.<br />

Regular expression syntax<br />

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

This section describes all of the elem<strong>en</strong>ts of ActionScript regular expression syntax. As you’ll see, regular expressions<br />

can have many complexities and nuances. You can find detailed resources on regular expressions on the web and in<br />

bookstores. Keep in mind that differ<strong>en</strong>t programming <strong>en</strong>vironm<strong>en</strong>ts implem<strong>en</strong>t regular expressions in differ<strong>en</strong>t ways.<br />

ActionScript 3.0 implem<strong>en</strong>ts regular expressions as defined in the ECMAScript edition 3 language specification<br />

(ECMA-262).<br />

G<strong>en</strong>erally, you use regular expressions that match more complicated patterns than a simple string of characters. For<br />

example, the following regular expression defines the pattern consisting of the letters A, B, and C in sequ<strong>en</strong>ce followed<br />

by any digit:<br />

/ABC\d/<br />

The \d code repres<strong>en</strong>ts “any digit.” The backslash (\) character is called the escape character, and combined with the<br />

character that follows it (in this case the letter d), it has special meaning in the regular expression.<br />

The following regular expression defines the pattern of the letters ABC followed by any number of digits (note the<br />

asterisk):<br />

/ABC\d*/<br />

The asterisk character (*) is a metacharacter. A metacharacter is a character that has special meaning in regular<br />

expressions. The asterisk is a specific type of metacharacter called a quantifier, which is used to quantify the amount<br />

of repetition of a character or group of characters. For more information, see “Quantifiers” on page 82.<br />

In addition to its pattern, a regular expression can contain flags, which specify how the regular expression is to be<br />

matched. For example, the following regular expression uses the i flag, which specifies that the regular expression<br />

ignores case s<strong>en</strong>sitivity in matching strings:<br />

/ABC\d*/i<br />

For more information, see “Flags and properties” on page 87.<br />

Last updated 6/6/2012<br />

77

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

Saved successfully!

Ooh no, something went wrong!