XML technologies / Regular expressions / How regex engines work / Pattern-matching basics
(Excerpt from "Regular expressions" by Jeffrey E. F. Friedl)
Before examining differences, let us consider what the engines share. Some transmission components are identical, or behave identically, and the following examples apply to all engine types.
The examples
This chapter assumes an ordinary but fully functional regex engine. Some examples may therefore fail in tools lacking particular constructs. My example car has its dipstick left of the oil filter; yours may put it behind the distributor. The goal is understanding the concepts so you can use your regex package, and perhaps appreciate those presented here.
Most examples will again use Perl and its notation. Occasional alternatives will demonstrate that notation is only surface detail and the underlying concept is independent of the tool. In short, I assume you have read Features and dialects (see table Constructs covered in this section) or will consult it when a construct looks unfamiliar.
This chapter explains how a regex engine tries to match a pattern. Convenient rules of thumb requiring no understanding would be nice, but are not possible. Condensed to the essentials, only two rules apply universally:
The earliest, leftmost-starting match wins.
Ordinary quantifiers (
˹*˼,˹+˼,˹?˼and˹{m,n}˼) are greedy.
We will examine these rules, their effects and more. Let us start with the first.
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