ULID in GO
Match 26-character ULIDs (Universally Unique Lexicographically Sortable Identifiers).
Try it in the GO tester →Pattern
regexGO
\b[0-9A-HJKMNP-TV-Z]{26}\b (flags: g)Go (RE2) code
goGo
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`\b[0-9A-HJKMNP-TV-Z]{26}\b`)
input := `01ARZ3NDEKTSV4RRFFQ69G5FAV`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
How the pattern works
ULIDs use Crockford Base32 which excludes I, L, O, U to avoid confusion. Exactly 26 characters, word-bounded.
Examples
Input
01ARZ3NDEKTSV4RRFFQ69G5FAVMatches
01ARZ3NDEKTSV4RRFFQ69G5FAV