Skip to content

Positive Lookaheads

Find expression xx where expression yy follows:-

Suppose you need to match all the first names ending with last name Picasso. You could write the following pattern to solve it.

([a-zA-Z ]+)(?=Picasso)

Regex Breakdown

Paloma Picasso // => true
Maya Picasso // => true
Steve Ross // => false

To experiment, navigate to the Regex101 sandbox I’ve created. This RegEx needs a backtracking engine (PCRE, JavaScript, Python, Java, .NET). Automata-based engines like RE2, Go’s regexp and Rust’s regex crate don’t support lookaheads.

Reading list

Thanks for reading.

Follow the RSS feed · Say hi on LinkedIn

Human Agent