© Zsolt Nagy 2018
Zsolt NagyRegex Quick Syntax Referencehttps://doi.org/10.1007/978-1-4842-3876-9_8

8. Lookahead and Lookbehind

Zsolt Nagy1 
(1)
Berlin, Germany
 

Anchors such as ^, $, and the \b boundary character are zero-length assertions that filter matches based on special conditions. These conditions restrict the position of the first or last character of the match. We will now do something similar, but this time, we will restrict the position of some characters in the expression with respect to other characters in the string. Lookahead and Lookbehind are two zero-length assertions that accomplish this.

For the sake of simplicity, we will restrict this chapter to PCRE-compatible languages and Perl 6.

Lookahead

A lookahead matches characters but reverts ...

Get Regex Quick Syntax Reference: Understanding and Using 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.