liveBook · Manning

Negative lookahead assertion

As explained in Secrets of the JavaScript Ninja, Third Edition

A negative lookahead is a regular-expression assertion that succeeds when its specified pattern does not occur ahead of the current position.

A negative lookahead is a regex assertion that succeeds when its specified pattern does not occur ahead of the current position. Its syntax is `(?!pattern)`, using `!` where positive lookahead uses `=`. section 12.6.1

(?!pattern)

Use this syntax to assert that a pattern does not occur later in the string. section 12.6.1

How Secrets of the JavaScript Ninja, Third Edition covers it

How deep it goes
Defines the assertion and gives its syntax, but supplies no negative-lookahead worked example.
Examples
Contrasts the negative syntax with positive-lookahead examples for armed-ninja matching and thousands grouping.
What you can do after
Understand how to recognize negative-lookahead syntax and interpret its exclusion test.
How it connects
Connects negative lookahead to positive lookahead and lookbehind as related regex features.

Also explained in

Compare how 2 books explain negative lookahead assertion →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Secrets of the JavaScript Ninja, Third Edition. The section links point to the parts of the book it draws on.