Regular Expressions
Regex syntax I always need to look up.
Lookaround
Lookahead
Match something ahead of something else:
const positive = /some(?=thing)/.test('something'); // trueconst positive = /some(?=thing)/.test('someone'); // falseconst negative = /some(?!thing)/.test('someone'); // trueconst negative = /some(?!thing)/.test('something'); // false
Lookbehind
Match something behind something else:
const positive = /(?<=some)thing/.test('something'); // trueconst positive = /(?<=some)thing/.test('anything'); // falseconst negative = /(?<!some)thing/.test('anything'); // trueconst negative = /(?<!some)thing/.test('something'); // false
The lookarounds themselves are not part of the match.