Vikash Kumar
Vikash Kumar

Reputation: 145

Regex to check of consecutive occurrence of same digit ignoring white spaces

I am writing a regex to check the consecutive occurrence of same digit in a number ignoring the white space between.

I have written 1{2,}|2{2,}|3{2,}|4{2,}|5{2,}|6{2,}|7{2,}|8{2,}|9{2,}|0{2,}

but this only checks if the occurrences don't have a space in between. How can I change it be ignore white spaces in between?

Test case:

1234 5678 9876 6543
2155 2174 9832 1349
4389 1234 5678 9876

in these test cases it should match 1st and second. 1st contains two 6s with a space in between. Second is a general case with two consecutive 5's Thanks.

Upvotes: 1

Views: 679

Answers (1)

Amadan
Amadan

Reputation: 198324

(\d)(?:\s*\1)+

Digit; then any number of spaces, then same digit - once or more.

Upvotes: 3

Related Questions