Chapter 4. Look Around
Until this point, we have learned different mechanisms of matching characters while discarding them. A character that is already matched cannot be compared again, and the only way to match any upcoming character is by discarding it.
The exceptions to this are a number of metacharacters we have studied, the so-called zero-width
assertions. These characters indicate positions rather than actual content. For instance, the caret symbol (^
) is a representation of the beginning of a line or the dollar sign ($
) for the end of a line. They just ensure that the position in the input is correct without actually consuming or matching any character.
A more powerful kind of zero-width assertion is look around, a mechanism with which it ...
Get Mastering Python Regular Expressions now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.