I want to create a regular expression to match the following:
L
: the set of all bit strings (ie strings over alphabet{0,1}
) that are divisible by4
If a binary is divisible by four, the last two bits are zero. So you can use this Regex to match:
/.+00$/
or, if you want to check that it is indeed a binary number (only zeros and ones), you can use:
/[01]+00$/
If you also want to match 0
and 00
:
/^(00?|[01]+00)$/
if you don't want to match all zeros, you can use:
/(?=1)[01]+00$/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.