Hi,I didn't go through all the ntmmecos above, but I don't think anyone actually explained why the regexp works, so I'll give it a try.The secret is in the representation of the number. The number is represented as a sequence of ones ('1 ) as long as the number. What the regexp does is try to see if this sequence of ones can be broken down into 2 or more equal parts . Wait a second, that's exactly like saying the number is divisible. The dividers are the length of the substring matched by (11+?) and the number of times it occurs in the original string.By the way, I agree that this is extremely inefficient. I also agree with @avinash that it's beautiful in a geekish sort of way .