How do I validate that a value is equal to the UUID4 generated by this code?
uuid.uuid4().hex
Should it be some regular expression? The values
Easy enough:
import re
uuid4hex = re.compile('[0-9a-f]{32}\Z', re.I)
This matches only for strings that are exactly 32 hexadecimal characters, provided you use the .match()
method (searches from the start of the string, see .search() vs. .match()). The \Z
matches the end of the string (vs. $
which would match at the end of a string or a newline).