D.7. Regular Expressions

The following tables provide information used with Perl's regular expressions and regex handling functions.

D.7.1. Matching Expressions and Characters

Expression/CharacterUse
.Matches an arbitrary character but not a newline.
(...)Groups a series of elements into a single element; that single element can be used as subexpressions (later referenced with $1 to $9 or \1 to \9, if matched).
^Matches the beginning of a line or the beginning of the pattern.
$Matches the end of a line.
[ ... ]Matches a class of characters. Use ^ to negate the class ( [^ ... ] ).
( ... | ... | ... )Matches one of the alternatives.
\characterEscape character.
(?# text )Use text as a comment.
(?: regexp )Similar to (regexp) but does not make back-references.
(?= regexp )Zero width, positive look-ahead assertion.
(?! regexp )Zero width, negative look-ahead assertion.
(? modifier )Embedded pattern-match modifier. The modifier can be one or more of the following: i, m, s, or x.

D.7.2. Match Count Modifiers

ModifierUse
+Matches the preceding character or pattern element one or more times.
?Matches the preceding character or pattern element zero or one times.
*Matches the preceding character or pattern element zero or more times.
{N,M}Matches the preceding character or pattern element a minimum of N and maximum of M match count. Use {N} for exactly N matches; use {N,} for at least N matches.

D.7.3. Escape Characters

Escaped CharacterUse
\wMatches alphanumeric (including underscore).
\WMatches nonalphanumeric. ...

Get Web Standards Programmer's Reference: HTML, CSS, JavaScript®, Perl, Python®, and PHP 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.