Regex to find repeating numbers

Viewed 70827

Can anyone help me or direct me to build a regex to validate repeating numbers

eg : 11111111, 2222, 99999999999, etc

It should validate for any length.

6 Answers

I used this expression to give me all phone numbers that are all the same digit.

Basically, it means to give 9 repetitions of the original first repetition of a given number, which results in 10 of the same number in a row.

([0-9])\1{9}

(\d)\1+? matches any digit repeating

you can get repeted text or numbers easily by backreference take a look on following example:

regexr.com

this code simply means whatever the pattern inside [] . ([inside pattern]) the \1 will go finding same as inside pattern forward to that.

Related