ulid / spec

The canonical spec for ulid
GNU General Public License v3.0
9.73k stars 174 forks source link

Question: regexp #94

Open vanodevium opened 11 months ago

vanodevium commented 11 months ago

Please provide correct regex for ULID. Thanx!

fabiolimace commented 11 months ago

Try this case-insensitive regex:

^[0-7][0123456789ABCDEFGHJKMNPQRSTVWXYZabcdefghjkmnpqrstvwxyz]{25}$
^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$

or this all-uppercase regex:

^[0-7][0123456789ABCDEFGHJKMNPQRSTVWXYZ]{25}$
^[0-7][0-9A-HJKMNP-TV-Z]{25}$

or this all-lowercase regex:

^[0-7][0123456789abcdefghjkmnpqrstvwxyz]{25}$
^[0-7][0-9a-hjkmnp-tv-z]{25}$

Note: the first character can only be one of these digits: 0, 1, 2, 3, 4, 5, 6, 7. That's why the regex starts with [0-7]. The remaining 25 characters are from the Crockford base-32 alphabet.