XML technologies / Regular expressions / Perl / Perl’s regex dialect / regex modifiers

(Excerpt from "Regular expressions" by Jeffrey E. F. Friedl)

With regex operators in Perl, you can specify regex modifiers after the final delimiter, for example i in m/.../i, s/.../.../i or qr/.../i. The following table lists the five general modifiers supported by all regex operators.

 

Table: general modifiers supported by all regex operators.

Modifier

Description

/i see Case-insensitive mode

Ignore letter case when matching

/x see Free-spacing mode

Free-spacing mode and comments

/s see Dot-matches-all mode

Dot matches everything

/m see Enhanced line-anchor or multiline mode

Enhanced anchor mode, multiline mode

/o see Regex compilation, /o, qr/.../ and efficiency

Compile the regex only once

The first four were covered in Features and dialects. These modifiers may also appear inside the regex using (?Modifikator) (see Mode modifiers) or apply only to a subexpression using (?Modifikator:...) (see Grouped mode modifiers). If specified both on the operator and inside the regex, the modifier inside the regex takes precedence.

The fifth general modifier, /o, primarily affects regex efficiency and is discussed separately later in this chapter (see Regex compilation, /o, qr/.../ and efficiency).

Multiple modifiers may follow the closing delimiter in any order. Programmers consequently waste much valuable time arranging them amusingly. For example, heute/kein/smog is valid Perl, assuming function heute exists. Match-operator modifiers may also repeat without changing meaning. The slash is not part of a modifier: instead of m/<title>/i, one can write m|<title>|i, m{<title>}i or m<<title>>i. Still, the conventional name is the “/i modifier”, even though the slash is clearly not part of it.

  

 

 

 

German edition copyright © 2008 by O’Reilly Verlag GmbH & Co. KG
You may print the online version for private use.
Otherwise, this chapter from "Reguläre Ausdrücke" is subject to the same terms as the bound edition: the work and all its parts are protected by copyright. All rights reserved, including reproduction, translation, microfilming, storage and processing in electronic systems.

O’Reilly Verlag GmbH & Co. KG, Balthasarstr. 81, 50670 Köln

back to top