Download Cheat sheet PDF 12 pages · syntax, editors, patterns, Unicode, performance, debugging
Pattern · India 🇮🇳

Regex for Indian state/UT 2-letter code

Official 2-letter codes for all Indian states and union territories.

The Indian state/UT 2-letter code regex is ^(AN|AP|AR|AS|BR|CG|CH|DH|DL|DN|GA|GJ|HP|HR|JH|JK|KA|KL|LA|LD|MH|ML|MN|MP|MZ|NL|OD|OR|PB|PY|RJ|SK|TN|TR|TS|UK|UP|WB)$ — copy it below, or open it in the explainer for a token-by-token breakdown.

The pattern

^(AN|AP|AR|AS|BR|CG|CH|DH|DL|DN|GA|GJ|HP|HR|JH|JK|KA|KL|LA|LD|MH|ML|MN|MP|MZ|NL|OD|OR|PB|PY|RJ|SK|TN|TR|TS|UK|UP|WB)$
Try in explainer → Download cheat sheet ↓

What it matches

  • MH
  • DL
  • KA
  • TN
  • UP
  • AP
  • TS
  • LA

What it doesn't match

  • XX
  • India
  • IN
  • M
  • MHN

Notes & gotchas

Official 2-letter state/UT codes used in vehicle plates, GSTIN prefixes (numeric equivalent), and ISO 3166-2:IN. Note OD/OR for Odisha (OD is current), TS for Telangana, LA for Ladakh (post-2019).

Code in your language

Use the explainer's Code tab to generate ready-to-paste snippets in JavaScript, Python, Java, .NET, Go, Ruby, and PHP for this pattern.

Open in explainer →

Token-by-token breakdown

Every part of the pattern, left to right:

TokenMeaning
^start of string (or line in multiline mode)
(start of a capturing group
ANliteral text “AN”
|OR — try the alternative
APliteral text “AP”
|OR — try the alternative
ARliteral text “AR”
|OR — try the alternative
ASliteral text “AS”
|OR — try the alternative
BRliteral text “BR”
|OR — try the alternative
CGliteral text “CG”
|OR — try the alternative
CHliteral text “CH”
|OR — try the alternative
DHliteral text “DH”
|OR — try the alternative
DLliteral text “DL”
|OR — try the alternative
DNliteral text “DN”
|OR — try the alternative
GAliteral text “GA”
|OR — try the alternative
GJliteral text “GJ”
|OR — try the alternative
HPliteral text “HP”
|OR — try the alternative
HRliteral text “HR”
|OR — try the alternative
JHliteral text “JH”
|OR — try the alternative
JKliteral text “JK”
|OR — try the alternative
KAliteral text “KA”
|OR — try the alternative
KLliteral text “KL”
|OR — try the alternative
LAliteral text “LA”
|OR — try the alternative
LDliteral text “LD”
|OR — try the alternative
MHliteral text “MH”
|OR — try the alternative
MLliteral text “ML”
|OR — try the alternative
MNliteral text “MN”
|OR — try the alternative
MPliteral text “MP”
|OR — try the alternative
MZliteral text “MZ”
|OR — try the alternative
NLliteral text “NL”
|OR — try the alternative
ODliteral text “OD”
|OR — try the alternative
ORliteral text “OR”
|OR — try the alternative
PBliteral text “PB”
|OR — try the alternative
PYliteral text “PY”
|OR — try the alternative
RJliteral text “RJ”
|OR — try the alternative
SKliteral text “SK”
|OR — try the alternative
TNliteral text “TN”
|OR — try the alternative
TRliteral text “TR”
|OR — try the alternative
TSliteral text “TS”
|OR — try the alternative
UKliteral text “UK”
|OR — try the alternative
UPliteral text “UP”
|OR — try the alternative
WBliteral text “WB”
)end of group
$end of string (or line in multiline mode)

About this pattern

India-specific identifiers are governed by various authorities (UIDAI for Aadhaar, Income Tax Dept for PAN, RBI for IFSC, GSTN for GSTIN, etc.). Regex confirms format; for definitive validation, integrate with the issuing authority's verification API.

Quick usage in different languages

This exact pattern — with the correct escaping and idioms for each language:

  • JavaScript: /^(AN|AP|AR|AS|BR|CG|CH|DH|DL|DN|GA|GJ|HP|HR|JH|JK|KA|KL|LA|LD|MH|ML|MN|MP|MZ|NL|OD|OR|PB|PY|RJ|SK|TN|TR|TS|UK|UP|WB)$/.test(value)
  • Python: re.match(r"^(AN|AP|AR|AS|BR|CG|CH|DH|DL|DN|GA|GJ|HP|HR|JH|JK|KA|KL|LA|LD|MH|ML|MN|MP|MZ|NL|OD|OR|PB|PY|RJ|SK|TN|TR|TS|UK|UP|WB)$", value)
  • Java: Pattern.compile("^(AN|AP|AR|AS|BR|CG|CH|DH|DL|DN|GA|GJ|HP|HR|JH|JK|KA|KL|LA|LD|MH|ML|MN|MP|MZ|NL|OD|OR|PB|PY|RJ|SK|TN|TR|TS|UK|UP|WB)$").matcher(value).matches()
  • C# / .NET: Regex.IsMatch(value, @"^(AN|AP|AR|AS|BR|CG|CH|DH|DL|DN|GA|GJ|HP|HR|JH|JK|KA|KL|LA|LD|MH|ML|MN|MP|MZ|NL|OD|OR|PB|PY|RJ|SK|TN|TR|TS|UK|UP|WB)$")
  • Go: regexp.MustCompile(`^(AN|AP|AR|AS|BR|CG|CH|DH|DL|DN|GA|GJ|HP|HR|JH|JK|KA|KL|LA|LD|MH|ML|MN|MP|MZ|NL|OD|OR|PB|PY|RJ|SK|TN|TR|TS|UK|UP|WB)$`).MatchString(value)
  • Ruby: /^(AN|AP|AR|AS|BR|CG|CH|DH|DL|DN|GA|GJ|HP|HR|JH|JK|KA|KL|LA|LD|MH|ML|MN|MP|MZ|NL|OD|OR|PB|PY|RJ|SK|TN|TR|TS|UK|UP|WB)$/.match?(value)
  • PHP: preg_match('~^(AN|AP|AR|AS|BR|CG|CH|DH|DL|DN|GA|GJ|HP|HR|JH|JK|KA|KL|LA|LD|MH|ML|MN|MP|MZ|NL|OD|OR|PB|PY|RJ|SK|TN|TR|TS|UK|UP|WB)$~', $value)

The explainer’s Code tab regenerates these for any pattern you paste, and the downloadable cheat sheet bundles the breakdown, all seven snippets, and the pitfalls below onto one printable page.

Common pitfalls

  • Anchored to the whole string. This pattern uses ^ and $, so it requires the entire input to match. To find it inside a longer text, drop the anchors and use the global (g) flag.
  • Validate beyond format. Matching the format doesn't guarantee the value is real. Confirm the indian state/ut 2-letter code against a source of truth (database, API, or checksum) where it matters.

Related patterns

More patterns in the India 🇮🇳 category:

See also

Browse all 300 patterns in the library, or open this regex in the interactive explainer to see a token-by-token breakdown, test against custom input, and generate code in seven languages.


More India patterns: Browse the full library →