User Guide
290 Using Regular Expressions
About metasequences
Metasequences are sequences of characters that have special meaning in a regular expression
pattern. The following table describes these metasequences:
[ and ] Defines a character class, which defines possible matches for a single
character:
/[aeiou]/ matches any one of the specified characters.
Within character classes, use the hyphen (-) to designate a range of
characters:
/[A-Z0-9]/ matches uppercase A through Z or 0 through 9.
Within character classes, insert a backslash to escape the ] and
- characters:
/[+\-]\d+/ matches either + or - before one or more digits.
Within character classes, other characters, which are normally
metacharacters, are treated as normal characters (not metacharacters),
without the need for a backslash:
/[$£]/ matches either $ or £.
For more information, see “Character classes” on page 291.
| (pipe) Used for alternation, to match either the part on the left side or the part
on the right side:
/abc|xyz/ matches either
abc or xyz.
Metasequence Description
{n}
{n,}
and
{n,n}
Specifies a numeric quantifier or quantifier range for the previous item:
/A{27}/ matches the character A repeated 27 times.
/A{3,}/ matches the character A repeated 3 or more times.
/A{3,5}/ matches the character A repeated 3 to 5 times.
For more information, see “Quantifiers” on page 293.
\b 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.
\B Matches at the position between two word characters. Also matches the
position between two nonword characters.
\d Matches a decimal digit.
\D Matches any character other than a digit.
\f Matches a form feed character.
\n Matches the newline character.
\r Matches the return character.
Metacharacter Description