JavaScript Lookbehind Assertions

Examples

Positive lookbehind assertion

Text preceding the current location must match the assertion
const RE_DOLLAR_PREFIX = /(?<=$)foo/g;
console.log(“bar %foo foo’

Negative lookbehind assertion

Text preceding the current location must not match the assertion
const RE_NO_DOLLAR_PREFIX = /(?<!$)foo/g;
console.log(“foo %bar bar’