ISO 4217 Currency Code in GO
Validate 3-letter ISO 4217 currency codes (USD, EUR, GBP, JPY, etc.) — structural check only.
Try it in the GO tester →Pattern
regexGO
^[A-Z]{3}$Go (RE2) code
goGo
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^[A-Z]{3}$`)
input := `USD`
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
^[A-Z]{3}$ requires exactly three uppercase letters, anchored to the full string. This validates the FORMAT but not the existence of the code — pair with a lookup table to ensure it's a real ISO 4217 entry like USD, EUR, GBP.
Examples
Input
USDMatches
USD
Input
JPYMatches
JPY
Input
usNo match
—