I would like it to match:
aaaaaa bb c
but not:
aaabaaa cd
...
Assuming the regex engine supports backlinks,
^(.)\1*$
In Java, it will be
theString.matches("(.)\\1*")
Using backlinks:
(.)(\1)*
Count: match any character followed by the same character 0 or more times.
Depending on the regexp mechanism and your needs, you can bind the regex only to the whole string, not substrings.
If you want to capture what you match, this is ^((.)\2*)$
^((.)\2*)$
Just to contribute to this question, you can use BackRefence:
(\ W +) \ S + \ 1
It checks for repeated words separated by spaces.