Needless to say, regex isn’t one of my strength. So, anyone has a better regex that the one I came with to validate the format of a canister id?
([a-z0-9]{5}-){4}[a-z0-9]{3}
Needless to say, regex isn’t one of my strength. So, anyone has a better regex that the one I came with to validate the format of a canister id?
([a-z0-9]{5}-){4}[a-z0-9]{3}
This is quite good and specific. You could also use (\w{5}-){4}\w{3}
, however it is less specific, since \w
also includes underscore.
Ah nice, that could be handy for a shorter version. Thanks for the share and feedback
^[a-zA-Z0-9]{5}-[a-zA-Z0-9]{5}-[a-zA-Z0-9]{5}-[a-zA-Z0-9]{5}-[a-zA-Z0-9]{3}$
The long version, but simple.
I included upper case because the Interface Spec says:
The textual representation is conventionally printed with lower case letters, but parsed case-insensitively.
Thanks for the hint about lower and upper case, did not knew!
The long but simple version of the regex is also neat.