My Regex:
^(\d)\1{2}.\1{3}.\1{3}-\1{2}$
Repetitions that aren't allowed:
000.000.000-00
111.111.111-11
222.222.222-22
333.333.333-33
444.444.444-44
555.555.555-55
666.666.666-66
888.888.888-88
999.999.999-99
It's working fine according to https://www.regex101.com/
So I'm trying to put it in Java, I already tried this way: ^(\\d)\\1{2}.\\1{3}.\\1{3}-\\1{2}$
, but definitely don't want to work.
My code:
if (hasTheSameDigits(cpfReplaced)) {
msg = "All the digits of informed CPF are equal.";
}
public boolean hasTheSameDigits(String cpf) {
return cpf.matches("^(\\d)\\1{2}\\1{3}\\1{3}\\1{2}$");
}
It would be great if someone could help me.