O'Reilly logo

Perl Pocket Reference, 5th 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

Regular Expression Patterns

The operator qr can be used to create patterns.

qr /pattern/ [ modifiers ]

Creates a pattern.

Patterns can also be created implicitly when using search and replace functions.

Modifiers can be used as indicated, but also inside of the pattern using {?modifiers). In this case, modifiers imsx can be switched on and off.

i

searches in a case-insensitive manner.

m

multiline mode: ^ and $ will match at embedded newline characters.

o

interpolates variables only once.

p

preserves ${^PREMATCH},${^MATCH} and ${^POSTMATCH}.

s

single-line mode: . will match embedded newline characters.

x

allows for whitespace and comments.

^

in (?^ . . . ), uses system defaults d-imsx.

These modifiers are mutually exclusive:

a

forces strict ASCII matching, repeat for stricter ASCII matching.

d

semantics depend on other settings.

l

treats the pattern with locale properties.

u

treats the pattern with full Unicode semantics.

perlre, perlretut, perlrequick, perlunicode.

The elements that form the pattern are based on regular expressions, but nowadays contain many nonregular extensions.

Basically each character matches itself, unless it is one of the special characters +?.*^$()[{|\. The special meaning of these characters can be escaped using a \.

.

Matches any character, but not a newline. In single-line mode, matches newlines as well.

( . . . )

Groups a series of pattern elements to a single element. The text the group ...

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