Backreference
A backreference is regular-expression or replacement-string notation that refers to text captured by a capturing group.
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
- regular expressionA regular expression is a formal pattern notation that describes sets of strings and specifies how text can be matched, searched, or transformed.
- regex groupingA regex capturing group is a parenthesized regular-expression subpattern whose matched text is retained for separate access or reference.
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.
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.


