“Write a regular expression that describes all strings of zeroes and ones representing binary numbers that are either odd or divisible by 8. The numbers may not have any leading zeros.”
I gave my answer as (000|1)$ which was marked wrong. I cannot see the reason why. Please explain! Thanks in advance.
You forgot two of the requirements.
It must contain only
1s and0s:There may be no leading
0s:If lookaheads are not allowed, it becomes a bit trickier:
Another addition, if you are allowed to use only the regular expression constructs that are available in “theoretical” regular expressions (alternation, group and repetition), it would look like this (anchors are implicit in this case):