Chapter 22. Regular Expressions
Each character matches itself, unless it is one of the special characters +?.*^$()[{|\. The special meaning of these characters can be escaped using a \.
The multiline and single-line modes are discussed in the section Chapter 23.
.Matches any character, but not a newline. In singleline mode, matches newlines as well.
( . . . )Groups a series of pattern elements to a single element. The text the group matches is captured for later use. It is also assigned immediately to
$^Nto be used during the match, e.g., in a(?{ ... }).^Matches the beginning of the target. In multiline mode, also matches after every newline character.
$Matches the end of the line, or before a final newline character. In multiline mode, also matches before every newline character.
[. . .]Denotes a class of characters to match.
[^. . .]negates the class.- ...
|...|... Matches the alternatives from left to right, until one succeeds.
(?#text)Comment.
(?[ modifier ] : pattern)Acts like
(pattern)but does not capture the text it matches. modifier can be one or more ofi,m,s, orx. Modifiers can be switched off by preceding the letter(s) with a minus sign, e.g.,si-xm. See page 37 for the meaning of the modifiers.(?=pattern)Zero-width positive look-ahead assertion.
(?!pattern)Zero-width negative look-ahead assertion.
(?<=pattern)Zero-width positive look-behind assertion.
(?<!pattern)Zero-width negative look-behind assertion.
(?{code})Executes Perl code while matching. Always ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access