Canister id regex

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.

1 Like

Ah nice, that could be handy for a shorter version. Thanks for the share and feedback

1 Like
^[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.

1 Like

I included upper case because the Interface Spec says:

The textual representation is conventionally printed with lower case letters, but parsed case-insensitively.

2 Likes

Thanks for the hint about lower and upper case, did not knew!

The long but simple version of the regex is also neat.

1 Like