Regex Backreference Tester
Backreferences are one of the most powerful regex features and one of the hardest to debug. (\w+)\s+\1 matches doubled words ("the the"). (?<tag>\w+).*</\k<tag>> matches an HTML tag that closes with the same name. This tester shows you exactly what your numbered or named backreferences capture and where they fire.
How to use the Regex Backreference Tester
Type your regex (with numbered \1, \2 or named \k<name> backreferences) and a test string. The tool finds every match, shows which captures fired, and what each backreference resolved to.
About Regex Backreference Tester
A regex capture group stores the matched substring. Backreferences let you reference an earlier capture later in the same pattern. Two forms:
- Numbered —
\1refers to the first()group,\2to the second, etc. - Named —
(?<tag>...)captures into a name;\k<tag>references it.
Backreferences are different from group references in replacement strings ($1) — backreferences are inside the pattern itself and must match the same text.
Performance note: backreferences make regex non-regular (in the formal language theory sense). Pattern engines fall back to backtracking, which can be much slower than DFA-based matching. Some engines (Go's regexp, RE2) don't support backreferences at all because they break linear-time guarantees.
Common use cases
- Doubled word detection — find repeated words in prose ("the the").
- Matched HTML tags — find <tag>...</tag> where opening and closing match.
- Palindrome detection — short palindromes via clever backrefs.
- Repeated patterns — find repeating ID sequences, doubled numbers.
- Quote matching — match strings where the opening and closing quote type are the same.