Lookahead
A lookahead is a regular-expression assertion that checks whether a pattern matches after the current position without consuming the checked input.
Secrets of the JavaScript Ninja, Third Edition
A lookahead is a regular-expression assertion that checks for a pattern immediately after the current position without consuming text.
- How it is used
- Checks whether later text satisfies a regex condition without consuming that text.
- How deep it goes
- Explains zero-length behavior through stepwise matching examples and practical applications.
- Examples
- Demonstrates finding names before weapon terms and inserting thousands separators into a number.
- What you can do after
- Apply lookahead with JavaScript regexes and String.matchAll or String.replace.
Read how Secrets of the JavaScript Ninja, Third Edition explains lookahead →
The Well-Grounded Rubyist, Fourth Edition
A lookahead assertion checks whether a specified subexpression follows the current position without consuming the checked characters.
- How it is used
- Filters matches by requiring following text without including that text in the matched result.
- How deep it goes
- Explains positive and negative syntax, zero-width behavior, consumption, and captures through a numeric example.
- Examples
- Uses /\d+(?=\.)/ against "123 456. 789" to demonstrate a nonconsuming period check.
- What you can do after
- Apply it via Ruby regexp syntax to require following text while leaving that text outside the match.
Read how The Well-Grounded Rubyist, Fourth Edition explains lookahead →
Related concepts
- assertionkind of · A regular-expression assertion tests a condition at a position in the input without consuming characters as part of the match.
- assertionkind of · A software assertion is an executable check of an expected condition or property that signals failure when the check does not hold.
- negative lookahead assertionincludes · A negative lookahead assertion is a regular-expression assertion that succeeds when its pattern does not match immediately after the current position without consuming characters.
- regular expressionpart of · A regular expression is a formal pattern notation that describes sets of strings and specifies how text can be matched, searched, or transformed.
Questions about lookahead
What is lookahead?
A lookahead is a regular-expression assertion that checks whether a pattern matches after the current position without consuming the checked input.
Which Manning books explain lookahead?
Secrets of the JavaScript Ninja, Third Edition and The Well-Grounded Rubyist, Fourth Edition.
What is the difference between lookahead and lookback?
A lookahead is a regular-expression assertion that checks whether a pattern matches after the current position without consuming the checked input. A pattern-matching operation that inspects preceding input without consuming it as part of the match.
What kinds of lookahead are there?
Kinds of lookahead include negative lookahead assertion.
What is lookahead a kind of?
Lookahead is a kind of assertion. A regular-expression assertion tests a condition at a position in the input without consuming characters as part of the match.
What is lookahead part of?
Lookahead is part of regular expression. A regular expression is a formal pattern notation that describes sets of strings and specifies how text can be matched, searched, or transformed.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

