Backreference
A backreference is regular-expression or replacement-string notation that refers to text captured by a capturing group.
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 →
Related concepts
- regex groupinguses · A regex capturing group is a parenthesized regular-expression subpattern whose matched text is retained for separate access or reference.
- regular expressionused by · A regular expression is a formal pattern notation that describes sets of strings and specifies how text can be matched, searched, or transformed.
- negative lookahead assertionused by · 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.
- regex engineused by · A regular-expression engine is software that interprets regular-expression patterns and applies them to text for matching, searching, splitting, or transformation.
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.

