Skip to content
Advertisement

What would be the Regex to match following 6 digit numbers?

The numbers should be 6 digit and of the form 0x0x0x or x0x0x0, where x can be any digit from 1 to 9. Ex – 202020, 030303, 808080, etc.

I have this regex that matches numbers with alternative 0 and 1s, cannot make it work for the above use case

b(?!d*(d)1)[10]+b

Advertisement

Answer

The easiest way is probably to capture the repeating part.
Then check if the back reference to group 1 is repeated.

b(0[1-9]|[1-9]0)1{2}b
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement