Skip to content
Regex

Backreferences

Reuse a previously captured group.

#backreference#capture

Code

regex
(\w)\1         repeated char (aa, bb)
(\w+)\s\1      repeated word
<(\w+)>.*?</\1>  matching HTML tag pair
([a-c])\1{2}   char repeated 3 times total
(?P<q>['"]).*?(?P=q)  quoted string (Python)
\1 \2 \3       backrefs to groups 1, 2, 3