I would like it to match:
aaaaaa
bb
c
but not:
aaabaaa
cd
...
Assuming the regex engine supports back-references,
^(.)\1*$
In Java it would be
theString.matches("(.)\\1*")
Using back references:
(.)(\1)*
Read: match any character followed by that same character 0 or more times.
Depending on the regexp engine and your needs, you might want to anchor the regex to only match the whole string, not substrings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With