liveBook · Manning

Assertion

A regular-expression assertion tests a condition at a position in the input without consuming characters as part of the match.

How 2 Manning books explain it

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

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.