Unicode Script Code (ISO 15924) Regex for Go
/^[A-Z][a-z]{3}$/What this pattern does
This page provides a lightweight, single-purpose regular expression for matching unicode script code (iso 15924), ported and verified for Go. A rigorously tested regex reduces debugging time and protects your application from edge-case failures. The snippet below is ready to drop into your Go project — whether you're validating in a Gin handler, a gRPC service, or a command-line tool.
Go Implementation
// Unicode Script Code (ISO 15924)
// ReDoS-safe | RegexVault — Localization > Locale & Language
package validation
import "regexp"
var unicodeScriptCodeIso15924Re = regexp.MustCompile(`^[A-Z][a-z]{3}$`)
func ValidateUnicodeScriptCodeIso15924(s string) bool {
return unicodeScriptCodeIso15924Re.MatchString(s)
}
// Example
// fmt.Println(ValidateUnicodeScriptCodeIso15924("Latn")) // trueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
Latn | LATN |
Hans | latn |
Hant | Lat |
Arab | Latin |
Cyrl | Lat1 |
Deva | — |
Hang | — |
Jpan | — |
Kore | — |
When to use this pattern
This pattern is drawn from the Localization > Locale & Language category and carries a ReDoS-safe certification. That matters for Go developers because Go's RE2 engine is inherently safe from catastrophic backtracking, but this pattern has been additionally verified for correctness. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.
Common Pitfalls
Script codes are title case (first letter uppercase, rest lowercase). They appear in the middle of BCP 47 tags: zh-Hant-TW (Traditional Chinese as used in Taiwan).
Technical Notes
ISO 15924 script codes: Latn=Latin, Hans=Simplified Chinese, Hant=Traditional Chinese, Arab=Arabic, Cyrl=Cyrillic, Deva=Devanagari (Hindi), Hang=Hangul, Jpan=Japanese (Han+Hiragana+Katakana). Used in BCP 47 language tags.
Have a pattern that belongs in the vault?
Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.
Submit a Pattern