User Guide
Regular expression syntax 289
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.
About metacharacters
The following table summarizes the metacharacters that you can use in regular expressions:
Metacharacter Description
^ (caret) Matches at the start of the string. With the m (multiline) flag set, the
caret matches the start of a line as well (see “The m (multiline) flag”
on page 300). Note that when used at the start of a character class, the
caret indicates negation, not the start of a string. For more information,
see“Character classes” on page 291.
$ (dollar sign) Matches at the end of the string. With the
m (multiline) flag set, $
matches the position before a newline (
\n) character as well. For more
information, see “The m (multiline) flag” on page 300.
\ (backslash) Escapes the special metacharacter meaning of special characters.
Also, use the backslash character if you want to use a forward slash
character in a regular expression literal, as in
/1\/2/ (to match the
character 1, followed by the forward slash character, followed by the
character 2).
. (dot) Matches any single character.
A dot matches a newline character (
\n) only if the s (dotall) flag is set.
For more information, see “The s (dotall) flag” on page 301.
* (star) Matches the previous item repeated zero or more times.
For more information, see “Quantifiers” on page 293.
+ (plus) Matches the previous item repeated one or more times.
For more information, see “Quantifiers” on page 293.
? (question mark) Matches the previous item repeated zero times or one time.
For more information, see “Quantifiers” on page 293.
( and ) Defines groups within the regular expression. Use groups for the
following:
• To confine the scope of the | alternator:
/(a|b|c)d/
• To define the scope of a quantifier: /(walla.){1,2}/
• In backreferences. For example, the
\1 in the following regular
expression matches whatever matched the first parenthetical group of
the pattern:
/(\w*) is repeated: \1/
For more information, see “Groups” on page 295.