I’m trying to search a big project for all examples of where I’ve declared an array with [48] as the size or any multiples of 48.
Can I use a regular expression function to find matches of 48 * n?
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here you go (In PHP’s PCRE syntax):
Usage:
Now, why it works:
Well we know that 48 is really just
3 * 16. And 16 is just2*2*2*2. So, any number divisible by 2^4 will have the 4 most bits in its binary representation 0. So by ending the regexp with0{4}$is equivalent to saying that the number is divisible by2^4(or16). So then, the bits to the left need to be divisible by 3. So using the regexp from this answer, we can tell if they are divisible by 3. So if the whole regexp matches, the number is divisible by both 3 and 16, and hence 48…QED…
(Note, the leading
0|case handles the failed match when$numberis 0). I’ve tested this on all numbers from0to48^5, and it correctly matches each time…