Supported Metacharacters

Perl supports the metacharacters and metasequences listed in Table 1-3 through Table 1-7. For expanded definitions of each metacharacter, see Section 1.2.1.

Table 1-3. Character representations

Sequence

Meaning

a

Alert (bell).



Backspace; supported only in character class.

e

ESC character, x1B.

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

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

f

Form feed, x0C.

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. Character classes and class-like constructs (continued)

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

Non-word character ,P{IsWord}.

d

Digit character, p{IsDigit}.

D

Non-digit character, P{IsDigit}.

s

Whitespace character, p{IsSpace}.

S

Non-whitespace character, P{IsSpace}.

p{prop}

Character contained by given Unicode property, script, or block.

P{prop}

Character not contained by given Unicode property, script, or block.

Table 1-5. Anchors and zero-width tests

Sequence

Meaning

^

Start of string, or after any newline in multiline match mode, /m.

A

Start of search string, in all match modes.

$

End of search string or before a string-ending newline, or before any newline in multiline match mode, /m.



End of string or before a string-ending newline, in any match mode.

z

End of string, in any match mode.

G

Beginning of current search.



Word boundary.

B

Not-word-boundary.

(?=...)

Positive lookahead.

(?!...)

Negative lookahead.

(?<=...)

Positive lookbehind; fixed-length only.

(?<!...)

Negative lookbehind; fixed-length only.

Table 1-6. Comments and mode modifiers (continued)

Modifier

Meaning

/i

Case-insensitive matching.

/m

^ and $ match next to embedded .

/s

Dot (.) matches newline.

/x

Ignore whitespace and allow comments (#) in pattern.

/o

Compile pattern only once.

(?mode)

Turn listed modes (xsmi) on for the rest of the subexpression.

(?-mode)

Turn listed modes (xsmi) off for the rest of the subexpression.

(?mode:...)

Turn listed modes (xsmi) on within parentheses.

(?-mode:...)

Turn listed modes (xsmi) off within parentheses.

(?#...)

Treat substring as a comment.

#...

Treat rest of line as a comment in /x mode.

u

Force next character to uppercase.

l

Force next character to lowercase.

U

Force all following characters to uppercase.

L

Force all following characters to lowercase.

Q

Quote all following regex metacharacters.

E

End a span started with U, L, or Q.

Table 1-7. Grouping, capturing, conditional, and control (continued)

Sequence

Meaning

(...)

Group subpattern and capture submatch into 1,2,... and $1, $2,....

n

Contains text matched by the nth capture group.

(?:...)

Groups subpattern, but does not capture submatch.

(?>...)

Disallow backtracking for text matched by subpattern.

...|...

Try subpatterns in alternation.

*

Match 0 or more times.

+

Match 1 or more times.

?

Match 1 or 0 times.

{n}

Match exactly n times.

{n,}

Match at least n times.

{x,y}

Match at least x times but no more than y times.

*?

Match 0 or more times, but as few times as possible.

+?

Match 1 or more times, but as few times as possible.

??

Match 0 or 1 time, but as few times as possible.

{n,}?

Match at least n times, but as few times as possible.

{x,y}?

Match at least x times, no more than y times, but as few times as possible .

(?(COND)...|...)

Match with if-then-else pattern where COND is an integer referring to either a backreference or a lookaround assertion.

(?(COND)...)

Match with if-then pattern.

(?{CODE})

Execute embedded Perl code.

(??{CODE})

Match regex from embedded Perl code.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.160.43