java - Regex to find exactly 11 repeating numbers -
my regex:
^(\d)\1{2}.\1{3}.\1{3}-\1{2}$ repetitions 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 https://www.regex101.com/
so i'm trying put in java, tried way: ^(\\d)\\1{2}.\\1{3}.\\1{3}-\\1{2}$, don't want work.
my code:
if (hasthesamedigits(cpfreplaced)) { msg = "all digits of informed cpf equal."; } public boolean hasthesamedigits(string cpf) { return cpf.matches("^(\\d)\\1{2}\\1{3}\\1{3}\\1{2}$"); } it great if me.
this regex should work: ([0-9])\1\1\.\1\1\1\.\1\1\1-\1\1\1.
(note: bloats java string because of escapes: "([0-9])\\1\\1\\.\\1\\1\\1\\.\\1\\1\\1-\\1\\1\\1".)
explanation:
([0-9]) finds digit.
\1 finds same digit. , again. , again. , again.
\. matches .
- matches -
Comments
Post a Comment