Joshua Wood Web Developer

Regular Expressions

Lookarounds

Lookarounds are useful when you want to match (or exclude) results based on what comes before or after the current position.

Name

Expression

Description

Lookahead

(?=pattern)

Asserts that the string following the current position is “pattern”

Negative Lookahead

(?!pattern)

Asserts that the string following the current position is not “pattern”

Lookbehind

(?<=pattern)

Asserts that the string preceding the current position is “pattern”

Negative Lookbehind

(?<!pattern)

Asserts that the string preceding the current position is not “pattern”