XML technologies / Regular expressions / Features and dialects / Maintenance⟦U+0003⟧ of regular expressions / Integrated approach

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

You already know the approach used by Perl from many examples, including this one from A small mail program:

if ($zeile =~ m/^Subject: (.*)/i) {
    $subject = $1;
}

For illustration, variables are italicized, regex operators are bold, and the regex itself is underlined. Perl applies regex ˹^Subject:●(.*)˼ to the text in variable $zeile. If it matches, the code in the following block executes. Within this block, variable $1 contains the text matched by the first and only parenthesized subexpression. This text is assigned to variable $subject.

Another common example of integration is regexes in configuration files, such as those used by procmail , a Unix mail-processing program. Regexes in its configuration select email messages and pass them to the relevant processing sections. This is simpler than Perl, because operands need not be specified: they are always the email messages.

Behind the scenes, much more happens. Integration simplifies the user’s work by hiding regex preparation and retrieval of results from a routine. However, hiding these steps can sometimes make particular cases less efficient or harder to use.

Before getting lost in details, let us see these hidden steps in the other approaches.

  

 

 

 

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