Lookaround in Regex

Posted on July 25, 2017

1 min read
Tags: programming regex

Lookarounds in regex are awesome non-capturing group. It is used to match pattern but not included in the matching list.

1. Lookahead Positive

Find expression A that is followed by expression B:

A(?=B)

2. Lookahead Negative

Find expression A that is followed not by expression B:

A(?!B)

3. Lookbehind Positive

Find expression A that is preceded by expression B:

(?<=B)A

4. Lookbehind Negative

Find expression A that is not preceded by expression B:

(?<!B)A