Match repeated text with PCRE2.
Section: PCRE2 features
Use a backreference
bash
bash
rg -P '\b(\w+)\s+\1\b' notes.txtExplanation
Backreferences are not supported by the default regex engine, so `-P` is required.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing PCRE2 features
Use the PCRE2 engine
Turn on advanced regex features such as look-around.
Use look-ahead assertions
Match only when text is followed by another fragment.
Use Unicode-aware classes
Search for letters with Unicode-aware semantics.
Search a literal pattern with PCRE2 multiline support
Match text spanning lines using a more powerful regex engine.