XML technologies / Regular expressions / Perl / Perl’s regex dialect / How regex literals are parsed
(Excerpt from "Regular expressions" by Jeffrey E. F. Friedl)
Usually, these features of regex literals in Perl are used without much thought. Perl generally does the right thing, one of its strengths. Only rarely must we understand the parsing in detail. Here are its individual steps:
The closing delimiter is located and any following modifiers (
/iand so on) are read. Depending on them, the remaining parsing may use free-spacing mode.Variables are interpolated.
With regex overloading, each literal part is passed to the overload routine. Interpolated variables separate these parts; the interpolated values themselves are not processed by that routine.
Without regex overloading,
\N{...}sequences are resolved.Case-conversion constructs (\
Q...\Eand so on) are applied.The result is passed to the regex engine.
This describes Perl’s behavior from an application programmer’s perspective. Internal processing is actually quite complex. In step 2, certain regex metacharacters must be distinguished from variables so that, for example, the underlined portion in ˹klipp$|klar$˼ is not interpreted as special variable $|.
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