How would you write a regular expression to define all strings of 0’s and 1’s that, as a binary number, represent an integer that is multiple of 3.
Some valid binary numbers would be:
11 110 1001 1100 1111
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.
Using the DFA here we can make a regular expression the following way, where A, B, C represent the states of the DFA.
Resulting in a PCRE regex like:
Perl test/example:
Outputs: