Backreferences
Advanced Regex - Lesson 2
20 min
Progress0/5
Understanding Backreferences
Concept
Backreferences allow you to refer to previously captured groups within the same pattern. \1 refers to the first group, \2 to the second, etc.
Example
(\w+)\s+\1 matches repeated words like "the the" (["']).+?\1 matches quoted strings with matching quotes
Practical Application
Perfect for finding duplicated content, matching pairs, and ensuring consistency