October 2006
Intermediate to advanced
888 pages
16h 55m
English
Naturally, a regular expression is matched against a string in a linear fashion (with backtracking as necessary). Therefore there is the concept of the “current location” in the string—rather like a file pointer or a cursor.
The term lookahead refers to a construct that matches a part of the string ahead of the current location. It is a zero-width assertion because even when a match succeeds, no part of the string is consumed (that is, the current location does not change).
In this next example, the string "New World" will be matched if it is followed by "Symphony" or "Dictionary"; however, the third word is not part of the match:
s1 = "New World Dictionary" s2 = "New World Symphony" s3 = "New World Order" ...
Read now
Unlock full access