O'Reilly logo

Perl Pocket Reference, 4th Edition by Johan Vromans

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 $^N to 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 of i, m, s, or x. 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required