RRegexBuilder
Get RegexBuilder

RegexBuilder · regex answers

Regex to find a repeated character

/(.)\1+/g

Capture any character, then require at least one more of the same via the backreference. Every run of two or more identical characters becomes a match, which is how you spot 'aaa' or a doubled separator without listing candidates.

What each part does

(.)capture one character
\1+one or more repetitions of that exact character

Tested against real input

Every row below was run through the engine when this page was built. The third column is the substring the pattern actually matched.

InputResultMatched
aaamatchesaaa
hellomatchesll
a--bmatches--
abcno match
ababno match

The mistake to avoid

Writing (.)\1{2,} when you meant three or more in total. The group already matched one, so {2,} means three or more overall — off-by-one lives here.

Try it on your own text

Paste this pattern and your input, see each match highlighted with its capture groups, step through what the engine did, and get the equivalent syntax for JavaScript, Python, Java, Go and PCRE.

Open RegexBuilder

Other regex answers