Assertion
A regular-expression assertion tests a condition at a position in the input without consuming characters as part of the match.
The Well-Grounded Rubyist, Fourth Edition
A zero-width assertion is a regular-expression condition that checks text or position without consuming any characters.
- How it is used
- Uses assertions to constrain regular-expression matches and to express expected outcomes in automated tests.
- How deep it goes
- Explains non-consumption, positional forms, lookaround syntax, and concrete tests without developing assertion internals.
- Examples
- Demonstrates comment-line filtering, lookaround patterns, and deck-of-cards tests using assert_equal.
- What you can do after
- Apply assertions to constrain Ruby regexp matches and verify Ruby program behavior with MiniTest.
Read how The Well-Grounded Rubyist, Fourth Edition explains assertion →
Secrets of the JavaScript Ninja, Third Edition
A zero-length assertion is a regular-expression construct that tests a condition at a position without consuming any characters in the match.
- How it is used
- Tests conditions at a string position without including the tested characters in the match.
- How deep it goes
- Defines assertions and illustrates two cases, then mentions lookaround without detailing its mechanics.
- Examples
- Uses `/\b/` to test a word boundary and `/^Z/` to illustrate a start assertion.
- What you can do after
- Evaluate whether a regex condition holds without consuming characters in the match.
Read how Secrets of the JavaScript Ninja, Third Edition explains assertion →
Related concepts
- lookaheadincludes · A lookahead is a regular-expression assertion that checks whether a pattern matches after the current position without consuming the checked input.
- lookbehind assertionincludes · A lookbehind assertion is a regular-expression assertion that checks whether a pattern matches before the current position without consuming the checked input.
- assert_equalimplemented by · assert_equal is a Minitest assertion method that compares an expected value with an actual value using Ruby equality.
- 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.
- non-capturing groupcontrasts with · A non-capturing group is a parenthesized regular-expression subpattern that groups matching behavior without storing matched text as a capture.
Questions about assertion
What is assertion?
A regular-expression assertion tests a condition at a position in the input without consuming characters as part of the match.
Which Manning books explain assertion?
The Well-Grounded Rubyist, Fourth Edition and Secrets of the JavaScript Ninja, Third Edition.
What is the difference between assertion and non-capturing group?
A regular-expression assertion tests a condition at a position in the input without consuming characters as part of the match. A non-capturing group is a parenthesized regular-expression subpattern that groups matching behavior without storing matched text as a capture.
What kinds of assertion are there?
Kinds of assertion include lookahead, lookbehind assertion, negative lookahead assertion and boundary assertion.
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.

