I need to write code in python's regexes that will pass with strings representing numbers that are divisible by 4. Every number that has last two numbers that are divisable by 4 is divisable by 4 (0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 84, 88, 92, 96): So I have written some code:
import re
r = re.compile('^([048]$)|([-]{0,1}[0-9]*([12]|[16]|[20]|[24]|[28]|[32]|[36]|[40]|[44]|[48]|[52]|[56]|[60]|[64]|[68]|[72]|[76]|[80]|[84]|[88]|[92]|[96])$)')
m = r.search("32") # this is oke
m.group() # this is giving a wanted result
m = r.search("33") # here somthing is not right
m.group() # it shouldn't return 33 but it does
Why does my code is not working as I wish to? Why does it accept 33?
See Question&Answers more detail:os