Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
Java 8

"
(\d){3}\.?\1{3}\.?\1{3}-?\1{2}
"
gm

Description

It matches CPF (Cadastro de Pessoa FĂ­sica) with all digits as the same number.

Since CPF consists in a pattern ###.###.###-##, or ###########, and # being a single digit, this document cannot have all the 11 (eleven) digits as the same number. Therefore 000.000.000.000-00 would not be an example of a CPF, since all 11 digits are the same number, in this case 0 (zero). This regular expression matches this case, where the cpf have all digit as the same number.

Submitted by TheRockSaysOP - 2 years ago (Last modified 2 years ago)