(original) (raw)
import re def checkUIDstring(string): # This routine will return ANY valid smedge UID from a string. # eg : f42e6be1-29bf-4f3c-ba58-1ae1d9ca5f88 # Each part is looking for a hex decimal a-f range of letters and a 0-9 number with the lengths # added in curly quotes after the filters with dashes in between each part. # Anything out of the range of these will fail. uidPattern = re.compile(('\w([a-f0-9]){7,8}\-\w[a-f0-9]{3}-\w[a-f0-9]{3}-\w[a-f0-9]{3}-\w[a-f0-9]{11}')) # damn it regular expressions rock! getMatch = uidPattern.search(string) match = False if getMatch: match = getMatch.group() return match goodString = "f42e6be1-29bf-4f3c-ba58-1ae1d9ca5f88" badString = "g42e6be1-29bf-4f3c-ba58-1ae1d9ca5f88" otherBadString = "fg2e6be1-29bf-4f3c-ba58-1ae1d9ca5f88" print checkUIDstring(goodString) print checkUIDstring(badString) print checkUIDstring(otherBadString)