Go (RE2)

ISO 3166-1 alpha-2 Country Code in GO

Validate 2-letter ISO 3166-1 alpha-2 country codes (US, GB, FR, JP, etc.) — structural check only.

Try it in the GO tester →

Pattern

regexGO
^[A-Z]{2}$

Go (RE2) code

goGo
package main

import (
	"fmt"
	"regexp"
)

func main() {
	re := regexp.MustCompile(`^[A-Z]{2}$`)
	input := `US`
	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]{2}$ requires exactly two uppercase letters anchored to the full string. Like the currency-code pattern, this verifies FORMAT not membership — combine with the official list to ensure the code actually exists.

Examples

Input

US

Matches

  • US

Input

GB

Matches

  • GB

Input

USA

No match

Same pattern, other engines

← Back to ISO 3166-1 alpha-2 Country Code overview (all engines)