XML technologies / Regular expressions / Perl / Unusual uses of Perl’s regex extensions / Problems with overloading regex literals
(Excerpt from "Regular expressions" by Jeffrey E. F. Friedl)
In theory, overloading literals in regexes is powerful and valuable, but practice differs. Only genuinely literal parts of a regex literal can be handled this way; interpolated elements cannot. For the regex in m/($MeinZeug)*+/, our function RegexLiteralVerarbeiten is called twice: once with the literal portion before interpolation (“(”), and once with the literal portion afterward (“)*+”). If $MeinZeug is a string containing a regex, its contents never reach the overload routine. Since our function needs both parentheses together, it fails to convert this possessive quantifier into atomic parentheses.
This mattered less with the earlier \< and \> example, because interpolated variables rarely split those sequences. Overloading affects only regex literals, never strings containing regexes; regex objects can handle those. Correctly processing a whole regex is often difficult, as the last section showed. Even our simple example using \> fails on a regex containing ›\\>‹, because it means not a word ending but a ›\‹ followed by a ›>‹.
The overload routine also cannot discover which modifiers are active. This is especially important for modifier /x , but the current implementation provides no way to determine it.
Overloading also prevents entering characters by their Unicode names (\N{Name}, see Unicode character names).
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