Backreference: a doubled letter
A regex exercise from Regexdrill. Solve it with a pattern box with live highlighting in your browser, checked against hidden test strings, and it is checked the moment you submit.
The task
A match anywhere counts. Match lines that contain the same lowercase letter twice in a row, like the ll in hello. Only letters count, and matching is case sensitive, so aA and 11 do not count.
What this exercise teaches
([a-z])\1 captures a letter and demands the identical letter next. [a-z]{2} would accept any two letters, and (\w)\1 would also accept doubled digits and underscores.
A hint if you get stuck
Capture one lowercase letter and follow it with \1, the backreference to that capture.
Try it now, free, no account needed
Every exercise on Regexdrill is free to try. Open it on the practice page, solve it, and get instant feedback with a hint. A free account adds the worked solution; Pro adds timed mode and the certificate.
Open this exerciseMore exercises in Groups and alternation
- Alternation: cat, dog or birdFree
- Alternation with anchorsFree
- Capture a standalone yearFree
- Group without capturingFree
- Backreference: doubled wordsFree
- Matching quote marksFree
- Optional group: phone extensionFree
- Repeated group: dotted numbersFree
- Alternation inside a groupFree
- Grouped alternatives: Mr, Mrs, Ms, DrFree
- Alternation precedence: image file namesFree
- Two captures: major and minor versionFree