liveBook · Manning

Backreference

A backreference is regular-expression or replacement-string notation that refers to text captured by a capturing group.

How 3 Manning books explain it

Secrets of the JavaScript Ninja, Third Edition

A backreference is a regular-expression construct that matches text previously captured by a capturing group.

How it is used
Matches repeated text within a JavaScript regular expression by referring to an earlier capture.
How deep it goes
Defines numbered syntax and works through character and doubled-word matches, without detailing regex-engine internals.
Examples
Uses matching characters around “a” and the repeated phrase “doki doki” to show exact reuse of captured text.
What you can do after
Apply it via JavaScript regular expressions to identify repeated substrings or whole words.

Read how Secrets of the JavaScript Ninja, Third Edition explains backreference →

Regular Expression Puzzles and AI Coding Assistants

A backreference is a regular-expression construct that matches the text previously captured by a specified capturing group.

How it is used
Enforces repeated captured text in regex puzzles involving connected dominoes, duplicate words, and growing encoded sequences.
How deep it goes
Works through numbered captures, lookaheads, quantifiers, and multi-pass validation, while leaving an alternative two-pattern approach as an exercise.
Examples
Tests domino plays, repeated-word strings, doubled @ runs, and Fibonacci-like @ sequences against candidate patterns.
What you can do after
Apply it via Python re to test equality constraints, then diagnose patterns with counterexamples and overlapping checks.

Read how Regular Expression Puzzles and AI Coding Assistants explains backreference →

Secrets of the JavaScript Ninja, Second Edition

A reference that reuses text previously matched by a capturing group.

How it is used
Enforces that later regex text matches an earlier capture, including matching corresponding opening and closing tag names.
How deep it goes
Defines numbered capture references and illustrates evaluation-time matching, while deferring fuller capture treatment.
Examples
Uses repeated d/t/n characters, simple markup tags, and numbered-digit matching exercises.
What you can do after
Apply a numbered backreference in a regex to require later text to repeat an earlier capture.

Read how Secrets of the JavaScript Ninja, Second Edition explains backreference →

Also covered in

What to know first

Related concepts

Questions about backreference

What is backreference?

A backreference is regular-expression or replacement-string notation that refers to text captured by a capturing group.

Which Manning books explain backreference?

Secrets of the JavaScript Ninja, Third Edition, Regular Expression Puzzles and AI Coding Assistants and Secrets of the JavaScript Ninja, Second Edition.

What should I know before learning backreference?

Manning books that teach backreference usually introduce regular expression and regex grouping first.

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.