Supported Metacharacters

Perl supports the metacharacters and metasequences listed in Table 3 through Table 7. To learn more about expanded definitions of each metacharacter, see "Regex Metacharacters, Modes, and Constructs.”

Table 1-3. Perl character representations

Sequence

Meaning

\a

Alert (bell).

\b

Backspace; supported only in character class (outside of character class matches a word boundary).

\e

Esc character, x1B.

\n

Newline; x0A on Unix and Windows, x0D on Mac OS 9.

\r

Carriage return; x0D on Unix and Windows, x0A on Mac OS 9.

\f

Form feed, x0C.

\t

Horizontal tab, x09.

\octal

Character specified by a two- or three-digit octal code.

\xhex

Character specified by a one- or two-digit hexadecimal code.

\x{hex}

Character specified by any hexadecimal code.

\cchar

Named control character.

\N{name}

A named character specified in the Unicode standard or listed in PATH_TO_PERLLIB/unicode/Names.txt; requires use charnames ':full'.

Table 1-4. Perl character classes and class-like constructs

Class

Meaning

[...]

A single character listed, or contained in a listed range.

[^...]

A single character not listed, and not contained within a listed range.

[:class:]

POSIX-style character class valid only within a regex character class.

.

Any character except newline (unless single-line mode, /s).

\C

One byte; however, this may corrupt a Unicode character stream.

\X

Base character, followed by any number of Unicode combining characters.

\w

Word character, \p{IsWord}.

\W

Nonword character, \P{IsWord}.

\d

Digit character, \p{IsDigit}.

Get Regular Expression Pocket Reference, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.