Regex for Matching Repeated Characters
Uses a backreference to match any character that immediately repeats itself.
Published October 13, 2026
Uses a backreference to match any character that immediately repeats itself.
Key points
- \1 refers back to whatever the first capture group matched, so (.)\1+ matches 2 or more of the same character in a row, like "aaa" or "!!"
Example
(.)\1+