Need a regular expression to recognize the 249 officially-assigned codes from the ISO 3166-1 alpha-2 and alpha-3 standards? Here they are!
ISO 3166-1 is a living standard and changes over time. This page is current as of November 11, 2024.
ISO 3166-1 alpha-2 Codes
This regex will match all 249 officially-assigned codes from the ISO 3166-1 alpha-2 standard.
\b(AD|AE|AF|AG|AI|AL|AM|AO|AQ|AR|AS|AT|AU|AW|AX|AZ|BA|BB|BD|BE|BF|BG|BH|BI|BJ|BL|BM|BN|BO|BQ|BR|BS|BT|BV|BW|BY|BZ|CA|CC|CD|CF|CG|CH|CI|CK|CL|CM|CN|CO|CR|CU|CV|CW|CX|CY|CZ|DE|DJ|DK|DM|DO|DZ|EC|EE|EG|EH|ER|ES|ET|FI|FJ|FK|FM|FO|FR|GA|GB|GD|GE|GF|GG|GH|GI|GL|GM|GN|GP|GQ|GR|GS|GT|GU|GW|GY|HK|HM|HN|HR|HT|HU|ID|IE|IL|IM|IN|IO|IQ|IR|IS|IT|JE|JM|JO|JP|KE|KG|KH|KI|KM|KN|KP|KR|KW|KY|KZ|LA|LB|LC|LI|LK|LR|LS|LT|LU|LV|LY|MA|MC|MD|ME|MF|MG|MH|MK|ML|MM|MN|MO|MP|MQ|MR|MS|MT|MU|MV|MW|MX|MY|MZ|NA|NC|NE|NF|NG|NI|NL|NO|NP|NR|NU|NZ|OM|PA|PE|PF|PG|PH|PK|PL|PM|PN|PR|PS|PT|PW|PY|QA|RE|RO|RS|RU|RW|SA|SB|SC|SD|SE|SG|SH|SI|SJ|SK|SL|SM|SN|SO|SR|SS|ST|SV|SX|SY|SZ|TC|TD|TF|TG|TH|TJ|TK|TL|TM|TN|TO|TR|TT|TV|TW|TZ|UA|UG|UM|US|UY|UZ|VA|VC|VE|VG|VI|VN|VU|WF|WS|YE|YT|ZA|ZM|ZW)\b
Note that this regex only matches the officially-assigned codes and not the user-assigned codes or the reserved code elements, which are all together only a small subset of the 676 total codes defined by the standard. However, this is the subset that most applications require. This is the subset of codes assigned to the nations of the world, which is what most applications require,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R|VNM|VUT|WLF|WSM|YEM|ZAF|ZMB|ZWE)\b
Note that this regex only matches the officially-assigned codes and not the user-assigned codes or the reserved code elements also defined by the standard. This is the subset of codes assigned to the nations of the world, which is what most applications require, but will not satisfy all use cases.
Data Source
The data was generated from the tables of the officially-assigned codes from the Wikipedia pages for the ISO 3166-1 alpha-2 and ISO 3166-1 alpha-3 pages.
License
Just in case anyone feels like they need a license, please consider this regex and file in the public domain under the Creative Commons CC0 license.
