Flash CS3 Documentation |
|||
| Programming ActionScript 3.0 > Using regular expressions > Regular expression syntax > Characters, metacharacters, and metasequences | |||
The simplest regular expression is one that matches a sequence of characters, as in the following example:
var pattern:RegExp = /hello/;
However, the following characters, known as metacharacters, have special meanings in regular expressions:
^ $ \ . * + ? ( ) [ ] { } |
For example, the following regular expression matches the letter A followed by zero or more instances of the letter B (the asterisk metacharacter indicates this repetition), followed by the letter C:
/AB*C/
To include a metacharacter without its special meaning in a regular expression pattern, you must use the backslash (\) escape character. For example, the following regular expression matches the letter A followed by the letter B, followed by an asterisk, followed by the letter C:
var pattern:RegExp = /AB\*C/;
A metasequence, like a metacharacter, has special meaning in a regular expression. A metasequence is made up of more than one character. The following sections provide details on using metacharacters and metasequences.
The following table summarizes the metacharacters that you can use in regular expressions:
|
Metacharacter |
Description |
|---|---|
|
|
Matches at the start of the string. With the |
|
|
Matches at the end of the string. With the |
|
|
Escapes the special metacharacter meaning of special characters. |
|
|
Matches any single character. A dot matches a newline character ( |
|
|
Matches the previous item repeated zero or more times. For more information, see Quantifiers. |
|
|
Matches the previous item repeated one or more times. For more information, see Quantifiers. |
|
|
Matches the previous item repeated zero times or one time. For more information, see Quantifiers. |
|
|
Defines groups within the regular expression. Use groups for the following:
For more information, see Groups. |
|
|
Defines a character class, which defines possible matches for a single character:
Within character classes, use the hyphen (
Within character classes, insert a backslash to escape the ] and
Within character classes, other characters, which are normally metacharacters, are treated as normal characters (not metacharacters), without the need for a backslash:
For more information, see Character classes. |
|
|
Used for alternation, to match either the part on the left side or the part on the right side:
|
Metasequences are sequences of characters that have special meaning in a regular expression pattern. The following table describes these metasequences:
|
Metasequence |
Description |
|---|---|
|
and
|
Specifies a numeric quantifier or quantifier range for the previous item:
For more information, see Quantifiers. |
|
|
Matches at the position between a word character and a nonword character. If the first or last character in the string is a word character, also matches the start or end of the string. |
|
|
Matches at the position between two word characters. Also matches the position between two nonword characters. |
|
|
Matches a decimal digit. |
|
|
Matches any character other than a digit. |
|
|
Matches a form feed character. |
|
|
Matches the newline character. |
|
|
Matches the return character. |
|
|
Matches any white-space character (a space, tab, newline, or return character). |
|
|
Matches any character other than a white-space character. |
|
|
Matches the tab character. |
|
|
Matches the Unicode character with the character code specified by the hexadecimal number nnnn. For example, |
|
|
Matches a vertical feed character. |
|
|
Matches a word character ( |
|
|
Matches any character other than a word character. |
|
|
Matches the character with the specified ASCII value, as defined by the hexadecimal number nn. |
Flash CS3