XML technologies / Regular expressions / Perl / Final thoughts
(Excerpt from "Regular expressions" by Jeffrey E. F. Friedl)
I think it is clear that I am very fond of Perl’s regular expressions, and with good reason, as I said at the beginning of Perl . Larry Wall, the author of Perl, was evidently guided by common sense and great inventiveness. Certainly, the implementation has its quirks, but I still enjoy the richness of the regex dialect and the way it is embedded in Perl.
But I am no blind fanatic: Perl lacks some features I would like. Since some wishes from the first edition of this book have come true, I am boldly making a few new ones. The most obvious omission is named capturing groups (see Named subexpressions). This chapter presented a way to emulate this functionality, but it has serious weaknesses; building named groups directly into the regex language would be much better. Set operations on character classes (see Set operations on character classes) would also be nice, although lookaround and some effort can emulate them (see Emulating class set operations with lookaround).
Then there are possessive quantifiers. Perl has atomic groups, which are even somewhat more versatile, but possessive quantifiers can make a regular expression clearer and more elegant in some situations. I would like both notations. I can also imagine two related constructs that I have not seen implemented anywhere. One would be a simple “forget!” metacharacter, such as ˹\v˼, which would immediately discard all saved states when reached. (This would make ˹x+\v˼ equivalent to the possessive ˹x++˼ or the atomic ˹(?>x+)˼.) The other metacharacter would explicitly prohibit the transmission from advancing. It would mean: “Either find a match along the path currently being followed, or fail altogether.” I suggest ˹\V˼ for this purpose.
More generally, I think that, in conjunction with ˹\V˼, being able to influence the transmission directly would be useful. This would make things such as those in Finding the leftmost-longest match much easier.
In Interpolating code patterns I already expressed the wish for finer control over how a code pattern is interpolated into a regex.
Perl is not the ideal language for regular expressions, but it comes very close, and it keeps improving.
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